[DBAL-352] Running doctrine:schema:update throws an exception the first time, succeeds the second time. Created: 25/Sep/12  Updated: 25/Sep/12

Status: Open
Project: Doctrine DBAL
Component/s: Schema Managers
Affects Version/s: None
Fix Version/s: None
Security Level: All

Type: Bug Priority: Minor
Reporter: Mark A. Hershberger Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
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
$



 Comments   
Comment by Christophe Coevoet [ 25/Sep/12 ]

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

Comment by Mark A. Hershberger [ 25/Sep/12 ]

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

Comment by Mark A. Hershberger [ 25/Sep/12 ]

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

$

Comment by Christophe Coevoet [ 25/Sep/12 ]

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;

Generated at Thu Dec 18 12:29:15 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.