Laravel迁移脚本生成多个主键列
以下迁移功能:Laravel迁移脚本生成多个主键列,laravel,laravel-5,laravel-5.4,Laravel,Laravel 5,Laravel 5.4,以下迁移功能: public function up() { Schema::create('translations', function (Blueprint $table) { $table->increments('id'); $table->string('table_name', 32); $table->string('column_name', 32); $table->intege
public function up()
{
Schema::create('translations', function (Blueprint $table) {
$table->increments('id');
$table->string('table_name', 32);
$table->string('column_name', 32);
$table->integer('foreign_key', 11)->unsigned();
$table->string('locale', 11);
$table->text('value');
$table->unique(['table_name', 'column_name', 'foreign_key', 'locale']);
$table->timestamps();
});
}
正在生成以下SQL查询:
create table `translations` (
`id` int unsigned not null auto_increment primary key,
`table_name` varchar(32) not null,
`column_name` varchar(32) not null,
`foreign_key` int unsigned not null auto_increment primary key,
`locale` varchar(11) not null,
`value` text not null,
`created_at` timestamp null,
`updated_at` timestamp null
) default character set utf8mb4 collate utf8mb4_unicode_ci engine = InnoDB ROW_FORMAT=DYNAMIC
请注意外键
字段上的附加自动增量主键
。这就是问题所在。如何更改迁移脚本,使其不会使外键
成为第二个自动增量主键
列
(如果这看起来很熟悉,这是的基本代码。)这是因为
integer()
方法的第二个参数是用于自动增量的步长值。不能设置整型列的长度,而是使用更适合您需要的列类型