Laravelでテーブル名をリネームするには
このupload_imagesをphotosという名前に変更しようと思って、
探していましたが、具体的な方法がようやく見つかったため、メモしておきます。
まずは、リネーム用のマイグレーションファイルを新たに作成します。
[vagrant@localhost nekopic_website]$ php artisan make:migration rename_upload_images_to_photos_table Created Migration: 2019_06_20_145539_rename_upload_images_to_photos_table
<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class RenameUploadImagesToPhotosTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { //ここをリネーム処理に ←が元の名前、→がリネーム後 Schema::rename('upload_images', 'photos'); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::table('photos', function (Blueprint $table) { // }); } }
最後にマイグレーションを反映させる。
[vagrant@localhost nekopic_website]$ php artisan migrate Migrating: 2019_06_20_145539_rename_upload_images_to_photos_table Migrated: 2019_06_20_145539_rename_upload_images_to_photos_table
リネームが完了しました。
参考サイト:
busy.org