下面的查询在我的本地主机上工作正常但是当我尝试在实时服务器上执行这个查询时它给出了 sql 错误
CREATE TABLE IF NOT EXISTS `tbl_claims` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`claimed_profile_id` int(11) NOT NULL,
`claimed_by_profile_id` int(11) NOT NULL COMMENT 'this will be only doctor''s profile id',
`name` varchar(100) NOT NULL,
`email` varchar(100) NOT NULL,
`phone_no` varchar(100) NOT NULL,
`status` enum('approved','disapproved','pending') NOT NULL DEFAULT 'pending',
`added_on` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
出现以下错误:
Invalid default value for 'added_on'
我不知道为什么上面的查询在 loalhost 中运行良好,而在实时服务器中却不能运行。
查询不工作的服务器有 PHP 版本 5.6.33
如有任何建议,我们将不胜感激。
最佳答案
我怀疑这是因为您试图将 CURRENT_TIMESTAMP
用作 datetime
字段的默认值。
The
DEFAULT
value clause in a data type specification indicates a default value for a column. With one exception, the default value must be a constant; it cannot be a function or an expression. This means, for example, that you cannot set the default for a date column to be the value of a function such asNOW()
orCURRENT_DATE
. The exception is that you can specifyCURRENT_TIMESTAMP
as the default forTIMESTAMP
andDATETIME
columns.
The
DEFAULT
value clause in a data type specification indicates a default value for a column. With one exception, the default value must be a constant; it cannot be a function or an expression. This means, for example, that you cannot set the default for a date column to be the value of a function such asNOW()
orCURRENT_DATE
. The exception is that you can specifyCURRENT_TIMESTAMP
as the default for aTIMESTAMP
column.
如您所见,对于 5.5 及以下版本,您只能使用 CURRENT_TIMESTAMP
作为 TIMESTAMP
字段的默认值。
关于mysql - 实时服务器中当前时间戳字段的默认值无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49009054/