Laravel Migration: Auto Enlarge key if not primary

I am trying to create a table with Laravel migrations, but I have problems. I just need to create a table with a primary pair ("id" and "revision"), being the "id" auto-increment. I can do this in MySQL, but I am unable to do this with Laravel Migrations, since increments () also sets the field as the main one. So far I have this:

Schema::create('bibliographies', function(Blueprint $table)
    {
        $table->increments('id');
        $table->integer('revision');
        ...
        $table->timestamps();
        $table->softDeletes();
        $table->primary(array('id', 'revision'));
    });

Note: changing the increments () method is not an option, since it is the core of Laravel.

Thank you for your help.

+4
source share
2 answers

:

$table->dropPrimary( 'id' );
$table->primary( array( 'id', 'revision' ) );
+5
 $table->unsignedInteger('id')->change();//will remove the auto increment
 $table->dropPrimary('id');//will remove primary constrain
 $table->unsignedInteger('revision') //add revision column
 $table->primary( array( 'id', 'revision' ) );//make them both primary
 $table->increments('id')->change()//add the auto increment constrain back  
0

All Articles