この問題の解決に誰か助けてくれますか?移行を実行した後laravel errno 150外部キー制約が正しく形成されていません
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
Schema::create('firms', function (Blueprint $table) {
$table->increments('id');
$table->string('title')->nullable();
$table->integer('user_id')->unsigned()->nullable();
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
});
Schema::create('jobs', function (Blueprint $table) {
$table->increments('id');
$table->string('title')->nullable();
$table->integer('firm_id')->unsigned()->nullable();
$table->foreign('firm_id')->references('id')->on('firms');
$table->timestamps();
});
エラー:
2つの外部キーを持つ3つのテーブルがあり、外部キーの場合は
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1005 Can't create table `job`.`#sql-5fc_a1`
(errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter ta
ble `firms` add constraint `firms_user_id_foreign` foreign key (`user_id`)
references `users` (`id`))
[PDOException]
SQLSTATE[HY000]: General error: 1005 Can't create table `job`.`#sql-5fc_a1`
(errno: 150 "Foreign key constraint is incorrectly formed")
残念ですが、機能しません:Schema :: create( 'firm'、function(Blueprint $ table){ $ table-> increments ( 'id'); $ table-> integer( 'firm_id') - > unsigned( ')'; unsigned();スキーマ:: create( 'ジョブ'、関数(Blueprint $テーブル){ $ table-> – Yrtymd
;これはうまくいきません:Schema :: create( 'firm'、function()); $ table-> foreign( 'firm_id') - >参照( ' < $ table-> increment( 'id'); $ table->増分( 'id');スキーマ:: create( 'ジョブ'、機能(ブループリント$テーブル){ $ table->整数( 'firm_id'); $ table-> foreign( 'firm_id') - >参照( 'id') - > on( '企業'); – Yrtymd