欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

[Illuminate\Database\QueryException] SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL : alter table `article_article_type` add constraint `article_article_type_a rticle_id_foreign` foreign key (`article_id`) 有大用

php artisan migrate 
报错

[Illuminate\Database\QueryException]
  SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL
  : alter table `article_article_type` add constraint `article_article_type_a
  rticle_id_foreign` foreign key (`article_id`) references `articles` (`artic
  le_id`) on delete cascade)
经查看migration ,要加上  unsigned(); 才不会报上面的错 
Schema::create('article_article_type', function (Blueprint $table) {
    $table->integer('article_id')->unsigned();
    $table->integer('article_type_id')->unsigned();
    $table->foreign('article_id')->references('article_id')->on('articles')->onDelete('cascade');
    $table->foreign('article_type_id')->references('article_type_id')->on('article_types')->onDelete('cascade');
    $table->primary(['article_id','article_type_id']);
});
 
普通分类: