gpt4 book ai didi

mysql - 将 Mysql 列默认值更改为 CURRENT_DATE 会出现错误?

转载 作者:行者123 更新时间:2023-11-29 13:01:30 25 4
gpt4 key购买 nike

ALTER TABLE `mysystem`.`projects` 
MODIFY COLUMN `project_capture_date` DATE NOT NULL DEFAULT CURRENT_DATE();

给出:

Error Code: 1064. You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server
version for the right syntax to use near 'CURRENT_DATE()'
at line 2

当前行定义:

project_capture_date, date, NO, , 0000-00-00

最近刚刚将引擎从 MyISAM 更改为 InnoDB

最佳答案

根据mysql文档

http://dev.mysql.com/doc/refman/5.0/en/data-type-defaults.html

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 as NOW() or CURRENT_DATE. The exception is that you can specify CURRENT_TIMESTAMP as the default for a TIMESTAMP

要解决此问题,您可能需要将数据类型定义为带有 DEFAULT CURRENT_TIMESTAMP 的 TIMESTAMP 列

<强> DEMO

如果您不需要 TIMESTAMP,则可以在插入时将列值设置为 Now()

关于mysql - 将 Mysql 列默认值更改为 CURRENT_DATE 会出现错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23269066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com