我正嘗試使用Laravel的遷移來創建外鍵。Laravel外鍵有什麼問題?
Schema::create('articles', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsinged();
$table->string('title');
$table->longText('body');
$table->timestamp('published_at');
$table->timestamps();
});
Schema::table('articles', function($table) {
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade');
});
我收到以下錯誤,當我做php artisan migrate
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter ta blelaravel_articles
add constraint articles_user_id_foreign foreign key (user_id
) referenceslaravel_users
(id
) on delete cascade) `
'unsinged();'?!? –
@MarkBaker不起作用! – Ahmad
這是相同的遷移嗎? – Dencker