0
0

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.

MySQL データを更新する度にcreated がupdateされちゃう件に関して

Posted at

問題:
Created(timestamp型)順でデータを表示。
カラムを修正した時Createdの時間も更新されてしまい
最下位に表示されるはずの一番古いデータが
最上位に表示されてしまう。
→不本意...

原因:
mysqlのtimestamp型には、デフォルトで
「CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP」
がついてきてしまう。

解決:ALTER TABLE テーブル名 CHANGE created created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;

*参考
https://blog.officekoma.co.jp/2016/11/mysql-timestamp.html

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?