【发布时间】:2017-05-06 16:37:08
【问题描述】:
为什么 laravel 模式回复
[照亮\数据库\查询异常] SQLSTATE[HY000]: 一般错误: 1005 Can't create table
test.#sql-13cc_d0(errno: 150 "外键约束格式不正确") (SQL: alter tablecitiesadd constrai ntcities_provinces_id_foreign外键(provinces_id)在删除级联时引用provinces(id)[PDOException] SQLSTATE[HY000]:一般错误:1005 无法创建 表
test.#sql-13cc_d0(errno: 150 "外键约束是 格式不正确")
第一张桌子
Schema::create('provinces', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->boolean('is_enable');
$table->boolean('is_deletable');
$table->boolean('is_editable');
$table->boolean('deleted');
$table->timestamps();
});
第二张桌子
Schema::create('cities', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->integer('province_id')->unsigned()->index();
$table->boolean('is_enable');
$table->boolean('is_deletable');
$table->boolean('is_editable');
$table->boolean('deleted');
$table->timestamps();
$table->foreign('province_id')
->references('id')->on('provinces')
->onDelete('cascade');
});
【问题讨论】:
标签: laravel laravel-5.2