enum型対策
public function __construct() { DB::getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); }
外部キー制約対策
//外部キー制約を一旦無効化 Schema::disableForeignKeyConstraints(); Schema::table(self::TABLE_NAME, function (Blueprint $table) { $table->bigInteger('member_id')->unsigned()->nullable()->default(null)->change(); }); //外部キー制約を有効化 Schema::enableForeignKeyConstraints();
<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\DB; class ModifyProfilesMemberIdNonNull extends Migration { /** * Run the migrations. * * @return void */ const TABLE_NAME = "member_profiles"; public function __construct() { DB::getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); } public function up() { DB::beginTransaction(); try { //外部キー制約を一旦無効化 Schema::disableForeignKeyConstraints(); Schema::table(self::TABLE_NAME, function (Blueprint $table) { $table->bigInteger('member_id')->unsigned()->nullable()->default(null)->change(); }); //外部キー制約を有効化 Schema::enableForeignKeyConstraints(); } catch (\Exception $e) { DB::rollback(); throw $e; } DB::commit(); } /** * Reverse the migrations. * * @return void */ public function down() { DB::beginTransaction(); try { //外部キー制約を一旦無効化 Schema::disableForeignKeyConstraints(); Schema::table(self::TABLE_NAME, function (Blueprint $table) { $table->bigInteger('member_id')->unsigned()->nullable(false)->change(); }); //外部キー制約を有効化 Schema::enableForeignKeyConstraints(); } catch (\Exception $e) { DB::rollback(); throw $e; } DB::commit(); } }