# Entity save cause error

**URL:** <https://discourse.cakephp.org/t/entity-save-cause-error/2645>\
**Category:** Need Help\
**Created:** [May 31, 2017, 2:39pm UTC](https://discourse.cakephp.org/t/entity-save-cause-error/2645 "2017-05-31T14:39:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrekat](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@andrekat](https://discourse.cakephp.org/u/andrekat)\
**Post date:** [May 31, 2017, 2:39pm UTC](https://discourse.cakephp.org/t/entity-save-cause-error/2645/1 "2017-05-31T14:39:31Z")

</div>

Hello!

While saving an entity locally works like a charm, it wont work on a remote server.  
I have already cleared the cache folder, even I synchronized both database schemata.

Error:

```
Error: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'program_type' cannot be null

```

If you are using SQL keywords as table column names, you can enable identifier quoting for your database connection in config/app.php.

SQL Query:

UPDATE channel\_programs SET time\_start = :c0 , time\_end = :c1 , date\_change = :c2 , all\_day = :c3 , program\_type = :c4 , program\_interval\_type = :c5 WHERE id = :c6

The entity in beforeSave method gives following output:

```
object(App\Model\Entity\ChannelProgram) {

'id' => (int) 4201,
'channel_id' => (int) 11,
'time_start' => object(Cake\I18n\Time) {

	'time' => '2017-05-30T01:00:00+02:00',
	'timezone' => 'Europe/Vienna',
	'fixedNowTime' => false

},
'time_end' => object(Cake\I18n\Time) {

	'time' => '2017-05-30T01:05:00+02:00',
	'timezone' => 'Europe/Vienna',
	'fixedNowTime' => false

},
'date_create' => object(Cake\I18n\FrozenTime) {

	'time' => '2017-05-31T16:31:32+00:00',
	'timezone' => 'UTC',
	'fixedNowTime' => false

},
'date_change' => object(Cake\I18n\Time) {

	'time' => '2017-05-31T16:34:37+02:00',
	'timezone' => 'Europe/Vienna',
	'fixedNowTime' => false

},
'all_day' => false,
'program_type' => 'spot',
'program_interval_type' => 'weekly',
'channel_program_dow' => object(App\Model\Entity\ChannelProgramDow) {

	'channel_program_id' => (int) 4201,
	'day' => 'tuesday',
	'date_create' => object(Cake\I18n\FrozenTime) {

		'time' => '2017-05-31T16:31:32+00:00',
		'timezone' => 'UTC',
		'fixedNowTime' => false
	
	},
	'date_change' => object(Cake\I18n\FrozenTime) {

		'time' => '2017-05-31T16:31:32+00:00',
		'timezone' => 'UTC',
		'fixedNowTime' => false
	
	},
	'[new]' => false,
	'[accessible]' => [
		'*' => true
	],
	'[dirty]' => [
		'day' => true
	],
	'[original]' => [
		'day' => 'monday'
	],
	'[virtual]' => [],
	'[errors]' => [],
	'[invalid]' => [],
	'[repository]' => 'ChannelProgramDows'

},
'[new]' => false,
'[accessible]' => [
	'*' => true
],
'[dirty]' => [
	'time_start' => true,
	'time_end' => true,
	'channel_program_dow' => true,
	'date_change' => true
],
'[original]' => [
	'time_start' => object(Cake\I18n\FrozenTime) {

		'time' => '2017-05-31T01:00:00+00:00',
		'timezone' => 'UTC',
		'fixedNowTime' => false
	
	},
	'time_end' => object(Cake\I18n\FrozenTime) {

		'time' => '2017-05-31T01:05:00+00:00',
		'timezone' => 'UTC',
		'fixedNowTime' => false
	
	},
	'date_change' => object(Cake\I18n\FrozenTime) {

		'time' => '2017-05-31T16:31:32+00:00',
		'timezone' => 'UTC',
		'fixedNowTime' => false
	
	}
],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'ChannelPrograms'

```

}

I cannot figure out what’s going on, since this field is definitly NOT NULL - it also works locally …

---

<div class="post-metadata">

**Author:** ![joris](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/joris/32/338_2.png) [@joris](https://discourse.cakephp.org/u/joris)\
**Post date:** [May 31, 2017, 8:44pm UTC](https://discourse.cakephp.org/t/entity-save-cause-error/2645/2 "2017-05-31T20:44:29Z")

</div>

Seems like `program_type` isn’t marked as dirty.

---

<div class="post-metadata">

**Author:** ![andrekat](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@andrekat](https://discourse.cakephp.org/u/andrekat)\
**Post date:** [May 31, 2017, 8:59pm UTC](https://discourse.cakephp.org/t/entity-save-cause-error/2645/3 "2017-05-31T20:59:50Z")

</div>

Well, actually I wont modify it - and it isnt modified. Thats the reason why I am wondering /:

---

<div class="post-metadata">

**Author:** ![aavrug](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/aavrug/32/178_2.png) [@aavrug](https://discourse.cakephp.org/u/aavrug)\
**Post date:** [June 1, 2017, 3:10am UTC](https://discourse.cakephp.org/t/entity-save-cause-error/2645/4 "2017-06-01T03:10:54Z")

</div>

This error shows most of the time when the table name is not defined with the field name and there can be same field name in two two different table which you are using. So try to use something like `channel_programs.program_type`.

---

<div class="post-metadata">

**Author:** ![andrekat](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@andrekat](https://discourse.cakephp.org/u/andrekat)\
**Post date:** [June 1, 2017, 8:14am UTC](https://discourse.cakephp.org/t/entity-save-cause-error/2645/5 "2017-06-01T08:14:57Z")

</div>

Thanks for your response.  
After your suggestion , I checked the table structure of channel\_programs:

```
Table: channel_programs

```

Columns:  
id int(11) AI PK  
channel\_id int(11)  
time\_start time  
time\_end time  
date\_create datetime  
date\_change datetime  
all\_day tinyint(1)  
program\_type enum(‘genre’,‘style’,‘event’,‘spot’,‘moderation’,‘trackloop’)  
program\_interval\_type enum(‘weekly’,‘period’)

So, the column is definitly available, also I checked if there is a second table with the same column name, but there isnt any other.

But … the output of the entity was printed at the start of the beforeSave method - I put it to the end, and behold: program\_type = null.

No I am going to figure out why this type is getting null - thank you so far!

Regards,

---

<div class="post-metadata">

**Author:** ![aavrug](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/aavrug/32/178_2.png) [@aavrug](https://discourse.cakephp.org/u/aavrug)\
**Post date:** [June 1, 2017, 8:54am UTC](https://discourse.cakephp.org/t/entity-save-cause-error/2645/6 "2017-06-01T08:54:42Z")

</div>

You can check if anything you are modifying in `beforeSave` if the program\_type is setting to null. Otherwise if the field is missing you can check in the relative entity file that the field name added to the accessible or not.
