0
0

More than 1 year has passed since last update.

【Laravel】timestamps()実行後、updated_atのみ削除する方法

Posted at

環境

Laravel v9.5.1 (PHP v8.1.3)

前提

最初のマイグレーション時の

$table->timestamps();

created_atupdated_atカラムが入っている状態。
updated_atカラムが不要になったので削除したい。

方法

新たなマイグレーションファイルを作成して、下記でマイグレーション実行する。
downメソッドも書き忘れずに!

    public function up()
    {
        Schema::table('posts', function (Blueprint $table) {
            $table->dropColumn('updated_at');
        });
    }

    public function down()
    {
        Schema::table('posts', function (Blueprint $table) {
            $table->timestamp('updated_at');
        }
    }

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