2020/06/14

[Laravel] 解決 Sqlite 在 migration 退版時發生不支援 dropColumn 或 renameColumn 多重呼叫的問題

問題

在 Laravel 使用 Sqlite 為資料庫使用, 執行 migration rollback 的時候發生下列錯誤訊息:

SQLite doesn't support multiple calls to dropColumn / renameColumn in a single modification.

發生原因

在 migration 的 down() 方法裡使用多個 dropColumn 但 Sqlite 不支援

$table->dropColumn('field1');
$table->dropColumn('field2');

解決方法

用 array() 方式來改寫 dropColumn 即可

$table->dropColumn([
    'field1',
    'field2',
]);

參考連結