参考) Laravel 6 Missing “subscribable_id” #102
composer でアップデートしたら、エラーが発生しました。
原因はデータベースのテーブル構造が変更になったためです。
インストール時には新規作成のmigrationファイルが使えますが、更新処理は手書きなので、メモ。今後もバージョンが上がると起こりうるので、注意。
対応方法は自前で更新migrationファイルを作成する
class ModifyPushSubscriptionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('push_subscriptions', function (Blueprint $table) {
//
$table->nullableMorphs('subscribable');
$table->string('content_encoding')->nullable();
$table->unsignedBigInteger('user_id')->nullable()->change();
});
DB::update("update push_subscriptions set subscribable_type = 'App\\\\User', subscribable_id = user_id");
Schema::table('push_subscriptions', function (Blueprint $table) {
//
$table->unsignedBigInteger('subscribable_id')->nullable(false)->change();
$table->string('subscribable_type')->nullable(false)->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
DB::update("update push_subscriptions set user_id = subscribable_id");
Schema::table('push_subscriptions', function (Blueprint $table) {
//
$table->dropMorphs('subscribable');
$table->dropColumn('content_encoding');
});
}
}