lundi 25 septembre 2017

Laravel migration script produces multiple primary key columns

The following migration function:

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();
    });
}

is producing the following SQL query:

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

Notice the additional auto_increment primary key on the foreign_key field. This is the problem. How do I alter the migrations script so that it does not make foreign_key a second auto_increment primary key column?

(In case this looks familiar, this is from the base code for Voyager.)



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2xr7R2t
via IFTTT

Aucun commentaire:

Enregistrer un commentaire