2
6

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.

laravelでchar型等のカラム属性を変更する

Posted at

少しハマったのでメモ

laravelのマイグレーションでchar型等のカラム属性をchangeメソッドで変更する事が出来ない。

Laravel 5.8 データベース:マイグレーション
https://readouble.com/laravel/5.8/ja/migrations.html
上記より抜粋↓
Note: 以降のカラムタイプのみ変更可能です:bigInteger、binary、boolean、date、dateTime、dateTimeTz、decimal、integer、json、longText、mediumText、smallInteger、string、text、time、unsignedBigInteger、unsignedInteger and unsignedSmallInteger

そのため、上記以外のカラムタイプの場合、下記のようにSQLを直接実行すればカラム属性を変更する事ができます。

        public function up()
        {
            DB::statement("
                ALTER TABLE <テーブル名>
                MODIFY <カラム名> <カラム属性>
            ");
        }
2
6
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
2
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?