May Sale! All accounts are 40% off this week.

aylara's avatar

Handling default date of 0000-00-00 when modernizing an old PHP app into Laravel

So I have some pretty-nasty old PHP code I'm trying to port to Laravel. Its got a lot of direct mysql queries and quite a lot expect default dates of '0000-00-00' in certain date fields.

Now I'm using mysql 5.6 in dev and even in production, I am able to set the flag to allow this type of date.

My migration file (created with a tool from exiisting database) is however throwing an error about this date, even though the underlying database doesn't mind it.

Is there a flag I can use to Laravel accept it and run migrations as expected?

0 likes
7 replies
aylara's avatar

Thanks a great deal. (Wonder why digitaldreams/laracrud generates timestamp by default for a pure date field.)

aylara's avatar

just looked at the code again and its actually not using timestamp:

$table->date('datefrom')->nullable()->default('0000-00-00');

So why is this failing, also when datetime('datefrom') is used?

Illuminate\Database\QueryException

SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'datefrom'...

aylara's avatar
aylara
OP
Best Answer
Level 3

ok, setting strict to false in database.php solved it!

MichalOravec's avatar

@aylara Better is to have null as a default value.

And zero value for datetime column is 0000-00-00 00:00:00

jlrdw's avatar

Perhaps create an issue at the digitaldreams/laracrud repo.

Please or to participate in this conversation.