错误 1067 EndDate 的默认值无效 [英] Error 1067 invalid default value for EndDate

查看:67
本文介绍了错误 1067 EndDate 的默认值无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能告诉我我在这个查询中遗漏了什么吗?它不断出现:

Can somebody tell me what I'm missing on this query? It keeps coming up with :

错误 1067:EndDate

CREATE TABLE `course_info`(
`student_id` VARCHAR (35),
`course_id` INT NOT NULL AUTO_INCREMENT, 
`name`      VARCHAR(45) NOT NULL,
`module`    VARCHAR(45) NOT NULL,
`StartDate` TIMESTAMP,
`EndDate`   TIMESTAMP,  
`course_Update` TIMESTAMP,
 PRIMARY KEY(`course_id`),
 FOREIGN KEY(`student_id`)
 REFERENCES student(`student_id`)
 )
 ENGINE = InnoDB;

推荐答案

你可以从官方文档:

NO_ZERO_DATE 模式影响服务器是否允许'0000-00-00'作为有效日期.它的效果还取决于是否使用了严格的 SQL 模式已启用.

The NO_ZERO_DATE mode affects whether the server permits '0000-00-00' as a valid date. Its effect also depends on whether strict SQL mode is enabled.

  • 如果未启用此模式,则允许使用0000-00-00"并且插入不会产生警告.
  • 如果启用此模式,则允许使用0000-00-00"并且插入会产生警告.
  • 如果启用此模式和严格模式,则不允许使用 '0000-00-00' 并且插入会产生错误,除非 IGNORE 被指定为出色地.对于 INSERT IGNORE 和 UPDATE IGNORE,允许使用 '0000-00-00'并插入会产生警告.

正如它所说,您可以使用 IGNORE 选项插入 0000-00-00 日期.那是为了插入.

As it says, you can insert 0000-00-00 dates with IGNORE option. That's for insertion.

在您的情况下,您所要做的就是将 NOT NULL 约束添加到您的 TIMESTAMP 字段以避免默认值 0000-00-00如下:

In your case, all what you have to do is to add the NOT NULL constraint to your TIMESTAMP fields in order to avoid the default value 0000-00-00 as follows:

StartDate TIMESTAMP NOT NULL,
EndDate TIMESTAMP NOT NULL,
course_Update TIMESTAMP NOT NULL,

编辑 1:

根据您的评论,如果您在 Linux 上,则需要编辑 my.cnf 文件,如果您在 Windows 上,则需要编辑 my.ini 文件以启用严格的 SQL 模式.您将在 SQL-mode 上找到如何做到这一点

Following your comment, you need to edit my.cnf file if you are on Linux or my.ini file if you are on Windows to enable the strict SQL mode. You will find how to do that on SQL-mode

这篇关于错误 1067 EndDate 的默认值无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆