我看到噸StackOverflow上的問題,但由於某些原因的答案並不適用於以下內容:錯誤1215;繼續得到本外鍵錯誤關於我的錯誤
我有三個表如下:
public function up()
{
Schema::create('activities_nl', function(Blueprint $table){
$table->increments('id');
$table->integer('activity_id')->unique();
$table->string('title');
$table->string('location');
$table->string('price');
$table->string('age_indication')->nullable();
$table->longText('registration')->nullable();
$table->longText('mandatory')->nullable();
$table->longText('description')->nullable();
$table->string('special_title')->nullable();
$table->string('academy')->nullable();
$table->timestamps();
$table->integer('en_table')->nullable();
$table->integer('de_table')->nullable();
});
}
public function up()
{
Schema::create('activities_de', function(Blueprint $table){
$table->increments('id');
$table->integer('activity_id')->unique();
$table->string('title');
$table->string('location');
$table->string('age_indication')->nullable();
$table->string('price');
$table->longText('registration')->nullable();
$table->longText('mandatory')->nullable();
$table->longText('description')->nullable();
$table->string('special_title')->nullable();
$table->string('academy')->nullable();
$table->timestamps();
$table->integer('nl_table')->nullable();
$table->integer('en_table')->nullable();
});
}
public function up()
{
Schema::create('activities_en', function(Blueprint $table){
$table->increments('id');
$table->integer('activity_id')->unique();
$table->string('title');
$table->string('location');
$table->string('age_indication')->nullable();
$table->string('price');
$table->longText('registration')->nullable();
$table->longText('mandatory')->nullable();
$table->longText('description')->nullable();
$table->string('special_title')->nullable();
$table->string('academy')->nullable();
$table->timestamps();
$table->integer('nl_table')->nullable();
$table->integer('de_table')->nullable();
});
}
我試圖通過increments('id')
而不是integer('activity_id)
來連接它們。下面是連接外鍵的遷移。
public function up()
{
Schema::table('activities_nl', function(Blueprint $table){
$table->foreign('en_table')->references('activity_id')->on('activities_en');
$table->foreign('de_table')->references('activity_id')->on('activities_de');
});
Schema::table('activities_de', function(Blueprint $table){
$table->foreign('en_table')->references('activity_id')->on('activities_en');
$table->foreign('nl_table')->references('activity_id')->on('activities_nl');
});
Schema::table('activities_en', function(Blueprint $table){
$table->foreign('nl_table')->references('activity_id')->on('activities_nl');
$table->foreign('de_table')->references('activity_id')->on('activities_de');
});
}
由於某種原因,我不斷收到一個外鍵約束..是不是因爲laravel不喜歡我試圖引用不同的ID?如果是的話,是有這一種變通方法..
還是純粹,我俯瞰拼錯?
編輯:從unsignedInteger改爲只爲整數,應該是國外的所有列。 編輯:添加 - >可空()來activity_id
所以這將是與其他列
編輯如出一轍:由於@shadow我想通了,沒有對ACTIVITY_ID沒有索引..我所要做的就是化妝它獨一無二。
什麼是你的問題在這裏... –
我不斷收到錯誤1215:不能添加外鍵約束 – Hoffie
可能的原因似乎activities_en表ACTIVITY_ID在activities_nl表中是可以爲空但不能爲空的...對於外鍵列數據類型長度和所有屬性應該是相同的。 –