General error: 1215 Cannot add foreign key constraint (SQL: alter table
iphpt_categories
add constraint iphpt_categories_art_id_foreign foreign key (art_id
) referencesarticle
(id
) on delete cascade on update cascade)
Schema::create('iphpt_categories', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->integer('art_id')->unsigned();
$table->integer('cate_id')->unsigned();
$table->foreign('art_id')->references('id')->on('iphpt_article');
$table->foreign('cate_id')->references('id')->on('iphpt_category');
$table->primary(['art_id', 'cate_id']);
});
建立文章标签与文章对应的表时报错 然后把
$table->integer('art_id')->unsigned(); $table->integer('cate_id')->unsigned();
里面加上10
$table->integer('art_id')->unsigned(10); $table->integer('cate_id')->unsigned(10);
然后就可以了!
运行这个语句前,iphpt_article 和 iphpt_category两个表必须存在,否则还会报错
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table
iphpt_tags
add constraint iphpt_tags_tag_id_foreign foreign key (tag_id
) referencesiphpt_tag
(id
))
当你能力不能满足你的野心的时候,你就该沉下心来学习