这是分类表的内容
Schema::create('classifies', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name')->comment('栏目名称');
$table->string('introduce')->comment('栏目介绍');
$table->integer('rank')->default('0')->comment('等级|0.顶级ID为0 1.二级ID为顶级ID');
$table->integer('state')->default('1')->comment('状态|1.正常 2.屏蔽');
$table->timestamps();
});
这是文章表的内容
Schema::create('classify_notices', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('title')->comment('公告名称');
$table->unsignedInteger('classify_id')->comment('公告所属分类');
// $table->foreign('被约束的字段')->references('约束的字段')->on('约束的表名')->onDelete('受此约束删除');
$table->foreign('classify_id')->references('id')->on('classifies')->onDelete('cascade');
//nullable()可以为空
$table->string('keyword')->nullable()->comment('关键字|SEO');
$table->text('bewrite')->nullable()->comment('描述|SEO');
$table->string('thumb')->comment('缩略图|image');
$table->integer('click')->comment('查看次数|input');
$table->mediumtext('content')->comment('内容|simditor');
$table->tinyInteger('iscommend')->default(2)->comment('推荐|radio|1:是,2:否');
$table->integer('state')->default('1')->comment('状态|1.正常 2.屏蔽');
$table->timestamps();
});
写完外键关联后,就报这个错误,语法什么的都对,问题是出在哪里呢?
SQLSTATE[HY000]: General error: 1005 Can't create table `ruijia`.`#sql-10a8_70` (errno: 150 "Foreign key constraint is incorr
ectly formed") (SQL: alter table `classify_notices` add constraint `classify_notices_classify_id_foreign` foreign key (`classify_id`) references `classifies` (`id`) on delete cascade)
感谢各位大神解答!