[DBAL-464] MySQL fails when try to drop a primary index with Auto Increment Created: 14/Mar/13  Updated: 10/Feb/15  Resolved: 18/Dec/13

Status: Resolved
Project: Doctrine DBAL
Component/s: None
Affects Version/s: 2.3.2
Fix Version/s: 2.5
Security Level: All

Type: Bug Priority: Minor
Reporter: Julien Rosset Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None

Linux (ubuntu), PHP 5.3.10, MySQL 5.5.29, Symfony2

Issue Links:
is referenced by DBAL-1132 [GH-786] Fix removing autoincrement c... Resolved


When an update of schema tries to drop a primary key with "auto increment" property (example : @ORM\GeneratedValue(strategy="AUTO")), the execution will fail : it say :
An exception occurred while executing 'ALTER TABLE odesadicola DROP PRIMARY KEY':

SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key

Apparently, this error occurs because Doctrine try to execute a "drop primary key" on a table and the resulting column of old primary key will be "auto increment".

The answer is to remove "auto increment" attribut of primary key column juste before try to drop the primary key itself.

Comment by Andreas Goetz [ 25/Jan/15 ]

I'm still seeing this problem in 2.5.1 on mysql. Any advice?

Comment by Steve Müller [ 26/Jan/15 ]

It has been fixed and the test case here is also passing: https://github.com/doctrine/dbal/blob/master/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php#L121-L145

Please provide more context and information to make the error reproducable. Thanks.

Comment by Andreas Goetz [ 26/Jan/15 ]

Only a partial fix, see https://github.com/andig/dbal/commit/bd07dced2bf4638d6e12c23a92b452922e8f173b

Comment by Andreas Goetz [ 26/Jan/15 ]

Sorry, I've meant https://github.com/doctrine/dbal/pull/786

Comment by Doctrine Bot [ 01/Feb/15 ]

A related Github Pull-Request [GH-786] was assigned:

Comment by Doctrine Bot [ 10/Feb/15 ]

A related Github Pull-Request [GH-786] was merged:

Generated at Tue Oct 13 03:19:12 EDT 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.