I have seen this several times. I have one server that allows me to insert some of the values, without specifying the others like so: INSERT INTO table SET value_a='a', value_b='b';
(value_c is a field that does not have a default value set, but it works fine here). When the script is moved to a new server some INSERT queries break because it requires the query to specify all non-default values, giving me the following error for the first occurrence of not specifying a non-default value:
#1364 - Field 'value_c' doesn't have a default value
Setting default values for the table might break functionality in other areas, otherwise I would just do that. I would love to know what exactly is going on here.
One of your servers is running in strict mode by default and the other not. If a server runs in strict mode (or you set it in your connection) and you try to insert a NULL value into a column defined as NOT NULL you will get #1364 error. Without strict mode your NULL value will be replaced with empty string or 0.
Example:
Will perform the following query:
On the following table
And you are doing the following query on it
So you are trying to insert a
null
value in anot null
column that does not have a default value listed. This is why you are getting the error.But why am I getting this error on server B and not on server A
Possible reasons are:
show create table table1
on each server and compare the output carefully.before insert
trigger present on server A but not on server B (or visa versa) that is changing the input you are inserting. do ashow triggers in databasex
on each server and compare the output.show create table
as the last line e.g.ENGINE=MyISAM
See: http://dev.mysql.com/doc/refman/5.0/en/show-triggers.html
http://dev.mysql.com/doc/refman/5.0/en/show-create-table.html