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

落花浮王杯 提交于 2019-12-05 01:39:18

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/20170823/how-set-default-value-to-now-with-sequel-pro

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!