CURRENT_TIMESTAMP\u7684\u4f7f\u7528<\/strong><\/div>\n\u4f17\u6240\u5468\u77e5\uff0cMySQL\u7684\u65e5\u671f\u7c7b\u578b\u53ef\u4ee5\u4f7f\u7528CURRENT_TIMESTAMP\u6765\u6307\u5b9a\u9ed8\u8ba4\u503c\uff0c\u4f46\u662f\u8fd9\u4e2a\u8ddfMySQL\u7684\u7248\u672c\u53ca\u65e5\u671f\u7684\u5177\u4f53\u7c7b\u578b\u6709\u5173\uff0c\u53ea\u67095.6\u4e4b\u540e\u7684\u7248\u672c\u624d\u80fd\u4f7f\u7528CURRENT_TIMESTAMP\u4f5c\u4e3aDATETIME\u7684\u9ed8\u8ba4\u503c\u3002<\/p>\n
\u4f8b\u5982\uff1a<\/p>\n
\r\nALTER TABLE t_user ADD update_time DATETIME DEFAULT CURRENT_TIMESTAMP\r\n<\/pre>\n\u57285.6\u4e4b\u524d\u7684\u7248\u672c\uff0c\u4f7f\u7528CURRENT_TIMESTAMP\u4f5c\u4e3a\u9ed8\u8ba4\u503c\u65f6\uff0c\u5c31\u4f1a\u51fa\u73b0\u4e0b\u9762\u7684\u9519\u8bef<\/p>\n
\r\n[Err] 1067 - Invalid default value for 'update_time'\r\n<\/pre>\n\u5728MySQL 5.6.5\u7248\u672c\u4e4b\u524d\uff0cDEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\u53ea\u9002\u7528\u4e8eTIMESTAMP\uff0c\u800c\u4e14\u4e00\u5f20\u8868\u4e2d\uff0c\u6700\u591a\u5141\u8bb8\u4e00\u4e2aTIMESTAMP\u5b57\u6bb5\u91c7\u7528\u8be5\u7279\u6027\u3002 \u4eceMySQL 5.6.5\u5f00\u59cb\uff0c DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\u540c\u65f6\u9002\u7528\u4e8eTIMESTAMP\u548cDATETIME\uff0c\u4e14\u4e0d\u9650\u5236\u6570\u91cf\u3002<\/p>\n
timestamp\u4f7f\u7528CURRENT_TIMESTAMP\u62a5\u9519<\/strong><\/div>\n\u9879\u76ee\u51fa\u73b0\u5982\u4e0b\u9519\u8bef\uff1a<\/p>\n
\r\nError updating database.\r\nCause:com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'createTime' cannot be null\r\n<\/pre>\n\u6570\u636e\u6a21\u578b\u5982\u4e0b\uff1a<\/p>\n
\r\n\/* \u521b\u5efa\u65f6\u95f4\u4e0d\u53ef\u4e3a\u7a7a*\/\r\ncreateTime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '\u521b\u5efa\u65f6\u95f4' ,\r\n\/* \u66f4\u65b0\u65f6\u95f4\u4e0d\u53ef\u4e3a\u7a7a*\/\r\nupdateTime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '\u66f4\u65b0\u65f6\u95f4' ,\r\n<\/pre>\n\u7ecf\u8fc7\u4e00\u7cfb\u5217\u7684\u95ee\u9898\u6392\u67e5\uff0c\u5b9a\u4f4d\u5230\u662f\u56e0\u4e3a\u4e0d\u540c\u7248\u672c\u7684MySQL\u6570\u636e\u5e93\u5168\u5c40\u53d8\u91cf\u201cexplicit_defaults_for_timestamp\u201d\u7684\u95ee\u9898\u3002<\/p>\n
\r\n-- \u67e5\u770bexplicit_defaults_for_timestamp\u9ed8\u8ba4\u503c\r\nSHOW GLOBAL VARIABLES LIKE \"explicit_defaults_for_timestamp\"; \r\n \r\n-- \u4fee\u6539explicit_defaults_for_timestamp\u9ed8\u8ba4\u503c\r\nSET @@global.explicit_defaults_for_timestamp=OFF;\r\n<\/pre>\n\u53c2\u6570\u503c\u4e3a\"ON\"\u7684\u60c5\u51b5\uff1a<\/p>\n
<\/p>\n","protected":false},"excerpt":{"rendered":"
\u4f17\u6240\u5468\u77e5\uff0cMySQL\u7684\u65e5\u671f\u7c7b\u578b\u53ef\u4ee5\u4f7f\u7528CURRENT_TIMESTAMP\u6765\u6307\u5b9a\u9ed8\u8ba4\u503c\uff0c\u4f46\u662f\u8fd9\u4e2a\u8ddfMySQL\u7684\u7248 […]<\/p>\n","protected":false},"author":668,"featured_media":15758,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-231128","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/231128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/668"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=231128"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/231128\/revisions"}],"predecessor-version":[{"id":231131,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/231128\/revisions\/231131"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/15758"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=231128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=231128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=231128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}