您好我在使用迁移架构生成器创建表时遇到问题。具有自引用外键的表出现问题。这是产生错误的代码:
Schema::create('cb_category', function($table)
{
$table->integer('id')->primary()->unique()->unsigned();
$table->integer('domain_id')->unsigned();
$table->foreign('domain_id')->references('id')->on('cb_domain');
$table->integer('parent_id')->nullable();
$table->foreign('parent_id')->references('id')->on('cb_category')->onUpdate('cascade')->onDelete('cascade');
$table->string('name');
$table->integer('level');
});
这是错误:
SQLSTATE[HY000]: General error: 1005 Can't create table 'eklik2.#sql-7d4_e' (errno: 150) (SQL: alter table `cb_cate
gory add constraint cb_category_parent_id_foreign foreign key (
parent_id ) references
cb_category (
id`)在更新级联上删除级联)(绑定:数组())
[PDOException] SQLSTATE[HY000]:一般错误:1005 无法创建表 'eklik2.#sql-7d4_e'(错误号:150)
任何的想法?