我正在尝试创建标签和文章之间的关系表,但遇到了问题。
迁移代码:
Schema::create('article_tag', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('article_id');
$table->unsignedBigInteger('tag_id');
$table->timestamps();
$table->foreign('article_id')->references('id')->on('articles')->onDelete('cascade');
$table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade');
});
错误:
SQLSTATE[HY000]: General error: 1005 Can't create table hiro_blog
.article_tag
(errno: 150 "Foreign key constraint is wronglyformed") (SQL: alter table article_tag
add constraint article_tag_article_id_foreign
外键 (article_id
) 在删除级联上引用 articles
(id
)