I'm trying to change the primary key on a table so I can use an other column as foreign key too.
Here's the migration for the creation
public function up()
{
Schema::create('blacklists', function (Blueprint $table) {
$table->id();
$table->integer('adv_id')->default(0);
// ...other columns
});
}
Then, I've made an other migration to change the adv_id column type in order to prepare the addition of a foreign key
public function up()
{
Schema::table('blacklists', function(Blueprint $table){
$table->integer('adv_id')->unsigned()->change();
});
}
Here's where I'm stocked
public function up()
{
Schema::table('blacklists', function(Blueprint $table) {
$table->dropPrimary('id');
$table->integer('adv_id')->primary()->change();
});
}
When I run the last migration, I got this error message
Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key (SQL: alter table `blacklists` drop primary key)