框架:Laravel 5.2 数据库:MySQL PHP:7.0
我有桌子“pops”:
Schema::create('pops', function (Blueprint $table) {
$table->string('id')->primary()->index();
$table->string('ab_test_parent_id')->nullable();
$table->string('cloned_parent_id')->nullable();
$table->timestamps();
});
和表“转换”:
Schema::create('conversions', function (Blueprint $table) {
$table->string('id')->primary()->index();
$table->integer('users')->default(null);
$table->string('name',256)->default(null);
$table->string('pop_id');
$table->foreign('pop_id')->references('id')->on('pops')->onDelete('cascade')->onUpdate('cascade');
$table->timestamps();
});
我在“转换”表中设置了一个外键(pop_id)。现在这是否意味着外键(pop_id)也是一个索引?如果不是…我需要做什么才能使其成为索引?
感谢?
原文由 Dani Banai 发布,翻译遵循 CC BY-SA 4.0 许可协议
这是一个完美的解决方案。
向上
下
修复迁移的建议
将上面替换为下面
并修复你的外键如下