【发布时间】:2013-09-01 20:06:39
【问题描述】:
我正在使用 Laravel 框架的迁移功能在数据库中创建外键。使用代码
Schema::table('posts', function($table){
$table->integer('category_id')->unsigned();
$table->foreign('category_id')
->references('id')
->on('categories');
});
产生 MySQL 输出(来自SHOW CREATE TABLE posts)
`category_id` int(10) unsigned NOT NULL,
KEY `posts_category_id_foreign` (`category_id`),
CONSTRAINT `posts_category_id_foreign` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`)
为什么 Laravel 在引用外键的列上使用 KEY 和 CONSTRAINT ... FOREIGN KEY ... REFERENCES ... 来创建新索引,而不是更常见的 FOREIGN KEY ... REFERENCES ...?
【问题讨论】: