【发布时间】:2019-08-22 12:00:03
【问题描述】:
外键不起作用。
这是我的迁移文件
Schema::create('course_prospect', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('prospect_id')->length(11)->unsigned();
$table->foreign('prospect_id')->references('id')->on('prospect');
$table->integer('course_id')->length(11)->unsigned();
$table->foreign('course_id')->references('course_id')->on('course');
$table->timestamps();
});
我收到了这个错误
Illuminate\Database\QueryException : SQLSTATE[HY000]: General error:
1005 Can't create table `customerinquirydb`.`#sql-104c_e9` (errno: 150
"Foreign key constraint is incorrectly formed") (SQL: alter table
`course_prospect` add constraint `course_prospect_prospect_id_foreign`
foreign key (`prospect_id`) references `prospect` (`id`))
【问题讨论】:
-
我认为在这一行中
id应该替换为prospect_id$table->foreign('prospect_id')->references('id')->on('prospect'); -
您也可以添加您的潜在客户和课程表吗?