Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How 'Set Default value' to 'NOW()' with Sequel PRO?

I have a MySQL table with some dates, I need that one of them have a default value equal to current time, I'm using 'Sequel Pro' to build the database, Then i wrote 'now()' (and 'GETDATE()') in default value, but doesn't work.

Can someone do help me, How 'Set Default value' to 'NOW()' with Sequel PRO?

ERROR:

An error occurred when trying to change the field 'DataDoPedido' via

ALTER TABLE Reserva CHANGE DataDoPedido DataDoPedido DATE NOT NULL DEFAULT 'now()'

MySQL said: Invalid default value for 'DataDoPedido'

thanks.

like image 839
Rui Martins Avatar asked Nov 24 '13 03:11

Rui Martins


1 Answers

For MySQL, the DEFAULT specified for a column must be a constant; it cannot be the return from a function. The one exception to this is the TIMESTAMP datatype, which can have a DEFAULT CURRENT_TIMESTAMP.

If you need to initialize a DATE column, one workaround is to create a BEFORE INSERT ON trigger.

like image 152
spencer7593 Avatar answered Nov 11 '22 02:11

spencer7593