9
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ERROR 1067 (42000): Invalid default value for 'created_at'

Last updated at Posted at 2018-02-21

問題

  SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default val
  ue for 'updated_at' (SQL: ALTER TABLE notices CHANGE created_at created_at
  timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP;)
SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default val
  ue for 'updated_at'

対策

/etc/my.cnfを変更

[mysqld]
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

※SET GLOBAL sql_mode = 'xxxx' でも変更可能だが、再起動するとシステム変数が戻ってしまうので、設定ファイルから変更

原因

 0000-00-00 00:00:00 を許容しないため?

背景

タイムスタンプのデフォルト値に実行日付を設定しようとしたら、
マイグレーションが完了しない。

環境

mysql 5.7.20
EC2 Linux (x86_64)

◆参考

システム変数の表示と変更
http://www.ksknet.net/mysql/post_102.html

9
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?