Doctrine DBAL
  1. Doctrine DBAL
  2. DBAL-352

Running doctrine:schema:update throws an exception the first time, succeeds the second time.

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Schema Managers
    • Security Level: All
    • Labels:
      None

      Description

      Shell output from my symfony project:
      $ app/console doctrine:schema:update --force
      Updating database schema...

      [Doctrine\DBAL\DBALException]
      An exception occurred while executing 'ALTER TABLE Tn ADD CONSTRAINT FK_3504C6F07D3656A4 FOREIGN KEY (account) REFERENCES Account (id)':

      SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'account' doesn't exist in table

      [PDOException]
      SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'account' doesn't exist in table

      doctrine:schema:update [--complete] [--dump-sql] [--force] [--em[="..."]]

      $ app/console doctrine:schema:update --force
      Updating database schema...
      Database schema updated successfully! "7" queries were executed
      $

        Activity

        Hide
        Christophe Coevoet added a comment - - edited

        Please run the command with the --dump-sql option instead of --force each time before launching it for real, to be able to see which SQL queries are executed in both cases

        Show
        Christophe Coevoet added a comment - - edited Please run the command with the --dump-sql option instead of --force each time before launching it for real, to be able to see which SQL queries are executed in both cases
        Hide
        Mark A. Hershberger added a comment -

        I'm not sure how to roll back the changes so that I can reproduce this.

        Show
        Mark A. Hershberger added a comment - I'm not sure how to roll back the changes so that I can reproduce this.
        Hide
        Mark A. Hershberger added a comment -

        Got it after a little poking around with git. Rolling back to a commit in my code before the one given here didn't didn't show this reproduce this.

        $ php app/console doctrine:schema:create
        ATTENTION: This operation should not be executed in a production environment.

        Creating database schema...
        Database schema created successfully!

        $ git checkout d686a39fb664dca540167e1b3e96ea0ffd67bc00
        Previous HEAD position was 0510a59... * First round of Customer-to-Accounts (1:n) mapping done * Start of Customer-to-Tn and Tn-to-Account mapping
        HEAD is now at d686a39... * A little debugging for Entity::Customer::hasEntitlement * Add FK for Customer to Tn

        $ php app/console doctrine:schema:update --dump-sql
        ALTER TABLE Account CHANGE guid guid VARCHAR(255) NOT NULL;
        ALTER TABLE Tn DROP FOREIGN KEY FK_3504C6F09B6B5FBA;
        DROP INDEX IDX_3504C6F09B6B5FBA ON Tn;
        ALTER TABLE Tn ADD tnType VARCHAR(10) NOT NULL, CHANGE account_id customer INT DEFAULT NULL;
        ALTER TABLE Tn ADD CONSTRAINT FK_3504C6F07D3656A4 FOREIGN KEY (account) REFERENCES Account (id);
        ALTER TABLE Tn ADD CONSTRAINT FK_3504C6F081398E09 FOREIGN KEY (customer) REFERENCES Customer (id);
        CREATE INDEX IDX_3504C6F07D3656A4 ON Tn (account);
        CREATE INDEX IDX_3504C6F081398E09 ON Tn (customer);
        ALTER TABLE Customer CHANGE guid guid VARCHAR(255) NOT NULL, CHANGE authGuid authGuid VARCHAR(255) NOT NULL
        mah@debian:~/comcast$ php app/console doctrine:schema:update --force
        Updating database schema...

        [Doctrine\DBAL\DBALException]
        An exception occurred while executing 'ALTER TABLE Tn ADD CONSTRAINT FK_3504C6F07D3656A4 FOREIGN KEY (account)
        REFERENCES Account (id)':

        SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'account' doesn't exist in table

        [PDOException]
        SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'account' doesn't exist in table

        doctrine:schema:update [--complete] [--dump-sql] [--force] [--em[="..."]]

        $ php app/console doctrine:schema:update --dump-sql
        ALTER TABLE Account CHANGE guid guid VARCHAR(255) NOT NULL;
        ALTER TABLE Tn ADD account INT DEFAULT NULL;
        ALTER TABLE Tn ADD CONSTRAINT FK_3504C6F07D3656A4 FOREIGN KEY (account) REFERENCES Account (id);
        ALTER TABLE Tn ADD CONSTRAINT FK_3504C6F081398E09 FOREIGN KEY (customer) REFERENCES Customer (id);
        CREATE INDEX IDX_3504C6F07D3656A4 ON Tn (account);
        CREATE INDEX IDX_3504C6F081398E09 ON Tn (customer);
        ALTER TABLE Customer CHANGE guid guid VARCHAR(255) NOT NULL, CHANGE authGuid authGuid VARCHAR(255) NOT NULL

        $ php app/console doctrine:schema:update --force
        Updating database schema...
        Database schema updated successfully! "7" queries were executed

        $

        Show
        Mark A. Hershberger added a comment - Got it after a little poking around with git. Rolling back to a commit in my code before the one given here didn't didn't show this reproduce this. $ php app/console doctrine:schema:create ATTENTION: This operation should not be executed in a production environment. Creating database schema... Database schema created successfully! $ git checkout d686a39fb664dca540167e1b3e96ea0ffd67bc00 Previous HEAD position was 0510a59... * First round of Customer-to-Accounts (1:n) mapping done * Start of Customer-to-Tn and Tn-to-Account mapping HEAD is now at d686a39... * A little debugging for Entity::Customer::hasEntitlement * Add FK for Customer to Tn $ php app/console doctrine:schema:update --dump-sql ALTER TABLE Account CHANGE guid guid VARCHAR(255) NOT NULL; ALTER TABLE Tn DROP FOREIGN KEY FK_3504C6F09B6B5FBA; DROP INDEX IDX_3504C6F09B6B5FBA ON Tn; ALTER TABLE Tn ADD tnType VARCHAR(10) NOT NULL, CHANGE account_id customer INT DEFAULT NULL; ALTER TABLE Tn ADD CONSTRAINT FK_3504C6F07D3656A4 FOREIGN KEY (account) REFERENCES Account (id); ALTER TABLE Tn ADD CONSTRAINT FK_3504C6F081398E09 FOREIGN KEY (customer) REFERENCES Customer (id); CREATE INDEX IDX_3504C6F07D3656A4 ON Tn (account); CREATE INDEX IDX_3504C6F081398E09 ON Tn (customer); ALTER TABLE Customer CHANGE guid guid VARCHAR(255) NOT NULL, CHANGE authGuid authGuid VARCHAR(255) NOT NULL mah@debian:~/comcast$ php app/console doctrine:schema:update --force Updating database schema... [Doctrine\DBAL\DBALException] An exception occurred while executing 'ALTER TABLE Tn ADD CONSTRAINT FK_3504C6F07D3656A4 FOREIGN KEY (account) REFERENCES Account (id)': SQLSTATE [42000] : Syntax error or access violation: 1072 Key column 'account' doesn't exist in table [PDOException] SQLSTATE [42000] : Syntax error or access violation: 1072 Key column 'account' doesn't exist in table doctrine:schema:update [--complete] [--dump-sql] [--force] [--em [="..."] ] $ php app/console doctrine:schema:update --dump-sql ALTER TABLE Account CHANGE guid guid VARCHAR(255) NOT NULL; ALTER TABLE Tn ADD account INT DEFAULT NULL; ALTER TABLE Tn ADD CONSTRAINT FK_3504C6F07D3656A4 FOREIGN KEY (account) REFERENCES Account (id); ALTER TABLE Tn ADD CONSTRAINT FK_3504C6F081398E09 FOREIGN KEY (customer) REFERENCES Customer (id); CREATE INDEX IDX_3504C6F07D3656A4 ON Tn (account); CREATE INDEX IDX_3504C6F081398E09 ON Tn (customer); ALTER TABLE Customer CHANGE guid guid VARCHAR(255) NOT NULL, CHANGE authGuid authGuid VARCHAR(255) NOT NULL $ php app/console doctrine:schema:update --force Updating database schema... Database schema updated successfully! "7" queries were executed $
        Hide
        Christophe Coevoet added a comment -

        hmm, the first update seems to miss the addition of the account field, which is done the second time through ALTER TABLE Tn ADD account INT DEFAULT NULL;

        Show
        Christophe Coevoet added a comment - hmm, the first update seems to miss the addition of the account field, which is done the second time through ALTER TABLE Tn ADD account INT DEFAULT NULL;

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Mark A. Hershberger
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated: