mac + mysql
在创建表的时候遇到了Invalid default value for 'created_at'的错误,不知道什么原因造成的。
CREATE TABLE `test` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` timestamp NOT NULL DEFAULT '1970-01-01 00:00:00',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
默认数据使用“0000-00-00 00:00:00”报错,使用“1970-01-01 00:00:00”也同样报错。
First of all, thank you for your help. After a lot of effort, I finally found the solution:
First use the following command to check sql_mode
If the query results are as follows:
If the result contains NO_ZERO_IN_DATE, NO_ZERO_DATE
, execute the following command:
timestamp is a number
1970-00-00 This is the date format
Different types
The character type timestamp has a range. If you want to use 0000-00-00 00:00:00, you can only use a string
You can refer to this blog of mine: http://www.cnblogs.com/chenmh/p/4565986....