Description
Q | A |
---|---|
Version | 4.2.x |
Background
In MySQL, if a column has the auto-increment attribute, it must be part of the primary key. If a user wants to drop a PK that includes an auto-increment column, they must drop the auto-increment first:
CREATE TABLE users (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(32)
);
ALTER TABLE users DROP PRIMARY KEY;
-- Incorrect table definition; there can be only one auto column and it must be defined as a key
The problem
DBAL wants to be helpful and drops the auto-increment attribute automatically (see MySQLSchemaManagerTest#testDropPrimaryKeyWithAutoincrementColumn()
). Due to the implementation details of this behavior, it might drop the auto-increment attribute even if it wasn't necessary (see #6836).
From the user's standpoint, it's quote non-obvious that a successful operation of dropping a PK will also result in the loss of auto-increment, so this is a bug. It can be fixed by removing the code that implements this behavior.
An attempt to perform a migration that would bring the table schema in an invalid state should be rejected by the database.