Doctrine DBAL
  1. Doctrine DBAL
  2. DBAL-400

can't add primary key to mysql table after the table is created

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.5, 2.4.2
    • Component/s: Platforms, Schema Managers
    • Security Level: All
    • 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

        Activity

        John Robeson created issue -
        John Robeson made changes -
        Field Original Value New Value
        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:
        {quote}
          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
        {quote}
        John Robeson made changes -
        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:
        {quote}
          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
        {quote}
        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:
         {quote}
        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;
         {quote}

        and says this:
        {quote}
          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
        {quote}
        Steve Müller made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.5 [ 10523 ]
        Resolution Fixed [ 1 ]
        Benjamin Eberlei made changes -
        Fix Version/s 2.4.2 [ 10620 ]

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            John Robeson
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: