Laravel5.5. migrate 提示外键约束错误?
In Connection.php line 664:
SQLSTATE[HY000]: General error: 1005 Can't create table n_fruit
.#sql-3fa0_23
(errno: 150 "Foreign key constrain
t is incorrectly formed") (SQL: alter table posts
add constraint posts_comment_id_foreign
foreign key (comment _id
) references comments
(id
) on delete cascade)
In Connection.php line 458:
SQLSTATE[HY000]: General error: 1005 Can't create table n_fruit
.#sql-3fa0_23
(errno: 150 "Foreign key constrain
t is incorrectly formed")
Process finished with exit code 1 at 13:53:34.
Execution time: 12,000 ms.
请问给位朋友这要怎么处理,下面是表字段设置
posts表
$table->integer('comment_id')->unsigned()->comment('评论id');
$table->integer('category_id')->unsigned()->comment('所属分类id');
$table->foreign('comment_id')
->references('id')
->on('comments')
->onDelete('cascade');
$table->foreign('category_id')
->references('id')->on('categorys')
->onDelete('cascade');
$table->timestamps();
comments表是存在的
推荐文章: