rugavy
2 years ago

Strange behaviour when migrating

Posted 2 years ago by rugavy

Hey, guys. Recently I encountered a strange situation, when tring to migrate a table on an SQL Server database.

I have a table which has a unique varchar of 6 chars as PK ( not my fault :) ) and another column (unsigned integer of 10 chars):

$table->string('id', 6)->primary();
... other columns here
$table->unsignedInteger('site_id', 10);

When tring to migrate the table I get an error:

 SQLSTATE[42000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Table 'customers' already has a primary key defined on it.

The problem is that when the table is being created, SQL Server automatically sets the site_id column as PK. After that it runs the alter table command, to set the id as PK and that is when the exception is being thrown.

Any idea/advice on how to make this work?

Thanks!

Please sign in or create an account to participate in this conversation.