【发布时间】:2017-01-30 08:44:21
【问题描述】:
我想为我的外键设置一个自定义名称。我能怎么做 ? 我正在使用下面的代码,但它让我出错:
SQLSTATE[42000]:语法错误或访问冲突:1072 键列 表中不存在“parent_section_id”(SQL:alter table
sections添加约束sections_parent_section_id _foreign外键 (parent_section_id) 引用sections(id) 删除级联)
我想要什么:
id - title - parent_section_id
parent_section_id引用当前id表
public function up()
{
Schema::create('sections', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->foreign('parent_section_id')->references('id')->on('sections')->onDelete('cascade');
$table->timestamps();
});
}
【问题讨论】: