我正在为 Laravel 使用 ClosureTable。我在迁移时遇到问题。
这是我的迁移脚本的样子:
//Page_Closure 迁移脚本
public function up()
{
Schema::table('page_closure', function(Blueprint $table)
{
$table->engine = 'InnoDB';
Schema::create('page_closure', function(Blueprint $t)
{
$t->increments('ctid');
$t->integer('ancestor', false, true);
$t->integer('descendant', false, true);
$t->integer('depth', false, true);
//problem after this line.
$t->foreign('ancestor')->references('id')->on('pages');
$t->foreign('descendant')->references('id')->on('pages');
});
});
}
创建外键时发生错误。IDK 为什么,但是根据我的迁移队列,“页面关闭”首先在“页面”脚本之前运行。
[Illuminate\Database\QueryException]
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'page_closure' already exists (SQL: create table `page_closure` (`ctid` int unsign
ed not null auto_increment primary key, `ancestor` int unsigned not null, `descendant` int unsigned not null, `depth` int unsigned not null) defa
ult character set utf8 collate utf8_unicode_ci)