migration機能でテーブルのカラム名を変更
1. マイグレーションファイルの作成
以下のコマンドを実行
php artisan make:migration rename_id_col_on_tests_table --table=tests
※ マイグレーションのファイル名指定はただの名前
rename~というファイル名を指定しても、空のマイグレーションファイルができる
2. マイグレーションファイルを変更
以下のように記述
public function up()
{
Schema::table('tests', function (Blueprint $table) {
$table->renameColumn('test_id', 'id');
});
}
3. マイグレーションを実行
以下のコマンドを実行
php artisan migrate
※なお、下記のエラーの対応法は ( 参考記事2 ) を参照
エラー
Class 'Doctrine\DBAL\Driver\PDOMySql\Driver' not found
解決
require doctrine/dbal ← このコマンドを実行
( 参考記事 )
( 参考記事2 )
0コメント