我正尝试使用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