Closed
Description
- Laravel Version: 7
- PHP Version: 7.3.14
- Database Driver & Version: MySQL 8
Description:
When MySQL has sql_require_primary_key
enabled, migrations that call ->primary()
on a column during table creation fail because it appears as though two queries are ran. One to create the table, and then a second to alter the table and add the primary key.
For context, DigitalOcean recently enforced primary keys on all newly created tables in their managed databases.
Steps To Reproduce:
- Ensure
sql_require_primary_key
is enabled on the MySQL server - Create a migration that creates a new table with a string as the primary key (we used
$table->string('string')->primary();
) and does not have a default$table->id();
column - Run the migration
The below error is generated when attempting to run the first query to create table.
General error: 3750 Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.