in your example
$table->unique(['owner_id', 'promoter_id']);
the first column in the array already has a foreign key and a related index.
The First option would be to put first a field that does not have a foreign key already, like
$table->unique(["key", 'owner_id', 'promoter_id']);
But it is not always possible
The second option - you just need to modify the down()
function
For example you create your unique index like this
$table->unique(['owner_id', 'promoter_id']);
owner_id
is the field that gives you troubles now because it goes the first in the array. Thus, the down
function should look like this:
$table->dropForeign(['owner_id']);
$table->dropUnique(['owner_id', 'promoter_id']);
$table->foreign('owner_id')->references('id')->on('owners');
The third option is a bit trickier, your 'down' function will look like this
$table->index('owner_id');
$table->dropUnique(['owner_id', 'promoter_id']);
It will work, but I don't recommend it, because it is not quite a `rollback'
If you start with index name records_owner_id_foreign
then you do php artisan migrate
and then php artisan migrate:rollback
and then you will find your index name records_owner_id_index
. It is not the same index name any more
So potentially you can have different index names in different databases, do you like it? I don't.