エラーが出たマイグレーション
- 既存の
orders.statusの型がstringだったのでtinyIntegerに変更したかった
Schema::table('orders', function (Blueprint $table) {
$table->tinyInteger('status')->default(0)->change();
});すると下記エラーが発生
SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "change"
LINE 1: alter table orders change column status status tinyint not n...
^ (SQL: alter table orders change column status status tinyint not null default 0)
tinyIntegerはchangeメソッドが使用できないらしい
(公式より)
Note: 以降のカラムタイプを変更できます。bigInteger、binary、boolean、date、dateTime、dateTimeTz、decimal、integer、json、longText、mediumText、smallInteger、string、text、time、unsignedBigInteger、unsignedInteger、unsignedSmallInteger、uuid対処法
SQLを直流しで対応した
DB::statement("ALTER TABLE orders CHANGE COLUMN status status TINYINT");PostgreSQLの場合は文法が違うため下記エラーが出る
SQLSTATE[HY000]: General error: 1 near "CHANGE": syntax error
下記コードで解決
DB::statement("ALTER TABLE orders ALTER COLUMN status TYPE SMALLINT USING(status::SMALLINT)");














Laravelのマイグレーションで、既存カラムをtinyIntegerに変更しようとしたところエラーが発生