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

Rui Martins picture Rui Martins · Nov 24, 2013 · Viewed 10.9k times · Source

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.

Answer

spencer7593 picture spencer7593 · Nov 24, 2013

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.