Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL error - Invalid datetime format: 1292 Incorrect datetime value: '' for column

I am using mysql in Os X 10.9.2 and when I try to run my php website in local I have this error:

Invalid datetime format: 1292 Incorrect datetime value: '' for column nameOfTheColumn

The Error happens when I tried to insert an empty value in a datetime field. The site works fine in production and in some other locals computers, so the problem is in database and I have to be solve in my local database. Reading about the problem I read that mysql could be running in Strict mode, so I edit /usr/local/mysql/my.cnf and I comment out this line:

 #sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

I restart computer and still is not working, but according to the documentation online and others questions, this is the way, but I would like to know What is it the exactly change I have to do to make my application works. Repeat, the code works in production, windows with xampp, etc... so can not be change because is to long and just for work in local I need the right change in MYSQL DATABASE.

Thanks in advance!

like image 268
daveloper Avatar asked May 10 '14 13:05

daveloper


1 Answers

It looks like the default sql_mode on your osx instance of MySQL is set to refuse invalid dates.

You could try issuing this command:

SET SESSION sql_mode='ALLOW_INVALID_DATES' 

as you initialize your session.

like image 102
O. Jones Avatar answered Sep 21 '22 02:09

O. Jones