Entity save cause error

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 …

Seems like program_type isn’t marked as dirty.

1 Like

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

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.

1 Like

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,

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.

1 Like