# CakePHP 4: 'Column' cannot be null, but default value defined in database

**URL:** https://discourse.cakephp.org/t/cakephp-4-column-cannot-be-null-but-default-value-defined-in-database/8517
**Category:** Need Help
**Tags:** help
**Created:** [October 16, 2020, 5:41pm UTC](https://discourse.cakephp.org/t/cakephp-4-column-cannot-be-null-but-default-value-defined-in-database/8517 "2020-10-16T17:41:24Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![Jawfin](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@Jawfin](https://discourse.cakephp.org/u/Jawfin)
#### Post date: [October 17, 2020, 5:57am UTC](https://discourse.cakephp.org/t/cakephp-4-column-cannot-be-null-but-default-value-defined-in-database/8517/2 "2020-10-17T05:57:37Z")

</div>

This isn’t the answer to your question, but more of a design approach. You’re mixing your technologies, in that using CakePHP for some default fields, and your Database for others. So I would be setting all default values in the CakePHP, in the `Model/table`. That way I only have one place to look and to check for those fields value.

A classic example is the timestamp where in your table you put created and modified fields, but you use your `initialize(}` `$this->addBehavior('Timestamp');` for the “default” values. This allows your app to work on different database paradigms, and someone else if they ever need to maintain it should follow your thinking.

But, as your question asks, I don’t know why it wouldn’t pull the table’s defaults - maybe track down the INSERT query CakePHP is creating to see if it is populating those fields will a null value.

---

_[View the full topic](https://discourse.cakephp.org/t/cakephp-4-column-cannot-be-null-but-default-value-defined-in-database/8517)._
