Tuesday, March 14, 2017

Laravel Schema: Null default, timestamp on update

I've just started working with Laravel so am getting used to how things are done.

I've been trying to do something that I cannot seem to find an example of online. I'm using the Schema builder to create a new table.

What I want is a datetime field with the default value to be NULL, but to have "ON UPDATE CURRENT_TIMESTAMP".

I've tried a number of things, but here was my latest attempt:

$table->dateTime('opened_on')->default(Capsule::raw('NULL ON UPDATE CURRENT_TIMESTAMP'));

With this code I get an "Invalid default value for 'opened_on'" error.

Any feedback or suggestions would be appreciated.



via Sherwin Flight

Advertisement