私はいくつかのテーブルに外部キーを追加していますが、これは機能しません。Laravel外部キーを追加するための移行は動作しません
Schema::table('users', function(Blueprint $table){
$table->integer('account_type')->unsigned()->change();
$table->foreign('account_type')
->references('id')
->on('account_types');
});
それは、端末でこれらの3つのエラーがスローされます。
[Illuminate\Database\QueryException] SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `users` add constraint `users_account_type_foreign` foreign key (`account_type`) references `account_types` (`id`))
[Doctrine\DBAL\Driver\PDOException]SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
[PDOException] SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
私はこの問題を解決するために何をする必要があるか任意のアイデア?私は自分のユーザーテーブルのaccount_typeフィールドをクリックして、SequelProを使用してaccount_typesテーブルの関連するアカウントタイプに移動することはできませんでした。
'account_types'を作成した後に移行' users'が作成されていますか?そうであれば、 'account_types'マイグレーションの日付を' users'より上になるように変更することをお勧めします。 – Classified
@Classifiedライブサーバー上にデータがあるので、すべての移行を再実行したくありません。その周りに他の方法はありませんか? – Lovelock
'account_types'テーブルを' users'テーブルの前に作成し、 'users'を変更する新しい移行を作成して外部関係を追加することができます。 – Classified