# __ .______ __ __ .______ .___________. ______ ______ .___ ___. # | | | _ \ | | | | | _ \ | | / | / __ \ | \/ | # | | | |_) | | |__| | | |_) | `---| |----` | ,----'| | | | | \ / | # | | | ___/ | __ | | ___/ | | | | | | | | | |\/| | # | | | | | | | | | | | | __ | `----.| `--' | | | | | # |__| | _| |__| |__| | _| |__| (__) \______| \______/ |__| |__| # ""$o o$"" ""$o o$" o "$""""o "o $" o""" $" "$o "$o" $o " $ o$" "$o $$$o$$$$o$$$$ $" "oooo o "" ""$$$$$$$$""o"" oo oooo" "$$$$$$oo"oo$$$o" o$$$$oo" o$$$o "o$$$$$$$ "$ $$$$$$$$$oo o$$$$$$$$$o"$" $ $$$ $$$$$$ o$$$$$$ "$$o"o $ $$$$o $$$$$$ $$$$$$$ $$$$o"o $ $$$$$ $$$$$" "$$$$$ $$$$$$ $ $o""""" """" """ """"""$" $ o$$$$$"""$$$$$"$$$$$""$$$$$ooo"o $ o"$o $$$$$$$$oo$$$$$$$$o $$"" $ oo$ "$$$$$$$$$$$$$$$$$$$$" o" o $oo o$$$"$ $$o"o $$$$$$$"" "$$$$$$$ o$$ $$$$o IPHPT BUG o$$$$" $ $$$$ o "$$$$$oo o$$$$$$ "o$$$$ $ $$$$$ o$$"" $ $$$$$o" "$$$$$$$$$$$$$ o o$$$$$o$ "" $$ $$" $ $$$" o"o$$$$$$$$$$$$ " "$$$ $ $$o o$$ "o $$ " $$$$$$$$$$$"o "$$ $ $$$ $$$ oo$ $ o""$$""$$$o " $"o$o $$$o o$$$$ o$$$"o"$oo$$$$o" o $o $$$$$oo$ $$$$o $$$$ $$$$ $$$$" $ $$$$$"" $$ o$$$ """$$$$"o" "$$$o "$$$o $$$" o """ $ $$$oo $$$$o" $$ o$$$"o" """"$ o$$$ o$" $$$ $ "$"" o$"o"$$o$$$$ "$$"o" o$$ "$oo $ " $$o $ "oo$"o$$$"o$o"$$$$o" o" $$$ ""$o $$ $$$o "o$$o$"$$"$$o$$o$$"$$o" $$$ ""o $$$ ""$$$ $$$$$$ $$$$ $" $$$$ $$ $$$$ $$$$"$$$o$ $"" $$$ $$$$ "$$$ """ $$$$ $$"" "$$ oo$" $ooo $ "$$ laravel 建数据库 迁移 的错误   -  叶落山城秋

laravel 建数据库 迁移 的错误

General error: 1215 Cannot add foreign key constraint (SQL: alter table iphpt_categories add constraint iphpt_categories_art_id_foreign foreign key (art_id) references article (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) references iphpt_tag (id))


欢迎转载,但请附上原文地址哦,尊重原创,谢谢大家 本文地址: https://www.iphpt.com/detail/3/
本站(PHP --> Golang)已重构,代码开源

当你能力不能满足你的野心的时候,你就该沉下心来学习