[DBAL-400] can't add primary key to mysql table after the table is created Created: 20/Dec/12  Updated: 20/Dec/13  Resolved: 28/Nov/13

Status: Resolved
Project: Doctrine DBAL
Component/s: Platforms, Schema Managers
Affects Version/s: None
Fix Version/s: 2.5, 2.4.2
Security Level: All

Type: Bug Priority: Minor
Reporter: John Robeson Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None


 Description   

A table in this application had no primary keys. I created an entity
so i could attempt to use the doctrine:schema:update command to fix it up.

When i attempted to add this:

  • @ORM\Id
  • @ORM\GeneratedValue(strategy="NONE")

to this:

  • @ORM\Column(name="session_id", type="string", length=128,
    nullable=false)

it generates SQL like this:

ALTER TABLE whos_online DROP INDEX idx_session_id_zen, ADD UNIQUE INDEX primary (session_id);
ALTER TABLE whos_online CHANGE ip_address ip_address VARCHAR(45) NOT NULL, CHANGE host_address host_address VARCHAR(512) NOT NULL;

and says this:

An exception occurred while executing 'ALTER TABLE whos_online DROP INDEX idx_session_id_zen, ADD UNIQUE INDEX primary (session_id );
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near 'primary (session_id)' at line 1



 Comments   
Comment by Steve Müller [ 28/Nov/13 ]

Fixed in PR:

https://github.com/doctrine/dbal/pull/435

Generated at Mon Nov 24 16:31:00 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.