简体   繁体   中英

Doctrine 2 and postgresql, database schema is not in sync

I'm using postgresql in a Symfony2 proyect with Postgis configured in Mac (not sure if that last one makes any difference).

The problem is that validating my schema AFTER running

doctrine:schema:update --force

will result on this error:

[Mapping] OK - The mapping files are correct.

[Database] FAIL - The database schema is not in sync with the current mapping file.

When updating again, Doctrine will try to add everything again, failing of course.

Thanks for the help.

EDIT: result for app/console --ansi doctrine:schema:update --dump-sql

ALTER T

ABLE actions ADD id VARCHAR(255) NOT NULL;
ALTER TABLE actions ADD display VARCHAR(255) NOT NULL;
ALTER TABLE actions ADD description VARCHAR(255) DEFAULT NULL;
ALTER TABLE actions ADD PRIMARY KEY (id);

-- lots more tables.. 

ALTER TABLE subclassifications ADD PRIMARY KEY (id);
ALTER TABLE users ADD id INT NOT NULL;
ALTER TABLE users ADD company_id INT DEFAULT NULL;
ALTER TABLE users ADD profile_id INT DEFAULT NULL;
ALTER TABLE users ADD name VARCHAR(255) NOT NULL;
ALTER TABLE users ADD password VARCHAR(255) NOT NULL;
ALTER TABLE users ADD salt VARCHAR(255) NOT NULL;
ALTER TABLE users ADD email VARCHAR(255) NOT NULL;
ALTER TABLE users ADD state INT NOT NULL;
ALTER TABLE users ADD accessCode INT NOT NULL;
ALTER TABLE users ADD CONSTRAINT FK_1483A5E9979B1AD6 FOREIGN KEY (company_id) REFERENCES companies (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE;
ALTER TABLE users ADD CONSTRAINT FK_1483A5E9CCFA12B8 FOREIGN KEY (profile_id) REFERENCES profiles (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE;
CREATE INDEX IDX_1483A5E9979B1AD6 ON users (company_id);
CREATE INDEX IDX_1483A5E9CCFA12B8 ON users (profile_id);
ALTER TABLE users ADD PRIMARY KEY (id);

The point here is that the same dump will work the first time, but when making any change, the dump should be only the incremental changes, not the complete database.

There are a few things that might be wrong here.

First one: which version of Doctrine are you using? Up until 2.3 I had the same thing. Updating to 2.4 fixed it.

Second one: Do you have columnDefinition anywhere in your mapping? If you have it, that's the problem. columnDefinition breaks portability. It also breaks Doctrine Migrations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM