【发布时间】:2020-08-12 03:45:06
【问题描述】:
我正在尝试添加一个包含两个外键的表,见下文:
Schema::create('semester_cohorts', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('semester_id');
$table->unsignedBigInteger('cohort_id');
$table->timestamps();
$table->foreign('semester_id')
->references('semesters')
->on('id')
->onDelete('cascade');
$table->foreign('cohort_id')
->references('id')
->on('cohorts')
->onDelete('cascade');
});
我收到以下消息:PDOException::("SQLSTATE[HY000]: General error: 1005 Can't create table [table name](errno: 150 "Foreign key constraint is incorrectly formed")"),尽管数据库中存在相应的引用表,但名称中没有拼写错误,并且主键/外键的类型匹配。什么可能导致这个问题?
`
【问题讨论】:
标签: php mysql laravel database-migration laravel-migrations