【发布时间】:2021-07-06 16:07:25
【问题描述】:
运行迁移时出现此错误
SQLSTATE[HY000]: 一般错误: 1005 Can't create table
tms-app.#sql-1e64_2b(errno: 150 "外键约束格式不正确") (SQL: alter tableprojectsadd constraintprojects_cout_id_foreign更新级联时外键 (cout_id) 引用couts(id)
这是项目表:
Schema::create('projects', function (Blueprint $table) {
$table->increments('id');
$table->string('libelle');
$table->string('libelle_long');
$table->string('direction');
$table->integer('cout_id')->unsigned();
$table->foreign('cout_id')
->references('id')->on('couts')
->onUpdate('cascade');
$table->foreign('status')
->referenecs('id')->on('statuses')
->onUpdate('cascade')
->onDelete('cascade');
$table->timestamps();
});
【问题讨论】:
-
欢迎来到 SO。请添加
couts表的迁移 -
迁移
couts表之前需要先迁移projects表
标签: laravel