简体   繁体   中英

doctrine mapping ok but not database validation

When updating my symfony 2 project's database, i encounter a strange issue.

$ php app/console doctrine:schema:validate
[Mapping]  OK - The mapping files are correct.
[Database] FAIL - The database schema is not in sync with the current mapping file.

despite running this

php app/console doctrine:schema:update --force

it always says that some queries have succesfully been executed, but schema:validate returns that the DB schema is not synced. What could make this?

symfony 2.4.2 mysql Ver 14.14 Distrib 5.5.37, for debian-linux-gnu (x86_64) using readline 6.2

EDIT: here is the dump of the doctrine:schema:update

ALTER TABLE melu_numeros ADD CONSTRAINT FK_8062E62AFB539063 FOREIGN KEY (id_fan) REFERENCES melu_fanzine (id_fan);
ALTER TABLE melu_numeros ADD CONSTRAINT FK_8062E62AABEDD0E7 FOREIGN KEY (id_num_fan) REFERENCES melu_formats (id_format);
ALTER TABLE melu_numeros ADD CONSTRAINT FK_8062E62AC06A9F55 FOREIGN KEY (img_id) REFERENCES Image (id);
ALTER TABLE melu_categories ADD CONSTRAINT FK_7B0247F1ABEDD0E7 FOREIGN KEY (id_num_fan) REFERENCES melu_numeros (id_num_fan);
ALTER TABLE melu_fichiers ADD CONSTRAINT FK_E2A048FCD6E65D60 FOREIGN KEY (id_agen) REFERENCES melu_agenda (id_agen);
ALTER TABLE melu_fanzine ADD CONSTRAINT FK_99AC1D58A656D38D FOREIGN KEY (id_asso) REFERENCES melu_association (id_asso);
ALTER TABLE melu_tarifs ADD CONSTRAINT FK_409B4C8D6E65D60 FOREIGN KEY (id_agen) REFERENCES melu_agenda (id_agen);
ALTER TABLE melu_newsletter CHANGE email email VARCHAR(50) NOT NULL;
ALTER TABLE melu_commentaire ADD CONSTRAINT FK_EE62B25DABEDD0E7 FOREIGN KEY (id_num_fan) REFERENCES melu_numeros (id_num_fan);
ALTER TABLE melu_contenus ADD CONSTRAINT FK_D9DCDC616C6AE4E2 FOREIGN KEY (id_cont) REFERENCES melu_types (id_types);
ALTER TABLE melu_types ADD CONSTRAINT FK_8AB9AD2AB7B5C800 FOREIGN KEY (id_types) REFERENCES melu_contenus (id_cont);
ALTER TABLE melu_photos ADD CONSTRAINT FK_F5C79087D6E65D60 FOREIGN KEY (id_agen) REFERENCES melu_agenda (id_agen);
ALTER TABLE melu_jour ADD CONSTRAINT FK_85C738A2D6E65D60 FOREIGN KEY (id_agen) REFERENCES melu_agenda (id_agen);
ALTER TABLE melu_util_droit ADD CONSTRAINT FK_6C66C28550EAE44 FOREIGN KEY (id_utilisateur) REFERENCES melu_utilisateurs (id_util);

You may have a field in you database which is not declared in your entity. You can try reverse engineering.

$ php app/console doctrine:mapping:convert xml ./src/Acme/BlogBundle/Resources/config/doctrine/metadata/orm --from-database --force
$ php app/console doctrine:mapping:import AcmeBlogBundle annotation

Be careful because it will override your actual entities. Reverse engineering is a one-time process to get started on a project so normally it shouldn't be done in the middle of a project.

Hope this will help you !

here too, doctrine can't handle foreign keys correctly since the tables were in myisam engine. i converted all in innoDb and everything works fine! thanks!

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