2017-09-25 60 views
0

以下迁移功能:Laravel迁移脚本产生多个主键列

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 

通知在foreign_key字段附加auto_increment primary key。这就是问题。如何更改迁移脚本,使其不会使第二个auto_increment primary key列成为foreign_key列?

(在情况下,这看起来很熟悉,这是来自于Voyager基本代码。)

回答