0
votes

I have some big problems with symfony and doctrine at the beginning of a new project. I have created database diagram with mysql workbench, inserted the sql into phpmyadmin and then I've tried symfony doctrine:build-schema to generate the YAML schema. It generates a wrong schema (relations don't have on delete/on update) and after this I've tried symfony doctrine:build --sql and symfony doctrine:insert-sql

The insert-sql statement generates error (can't create table ... failing query alter table add constraint ....), so I've decided to take a look over the generated sql and I've found out some differences between the sql generated from mysql workbench (which works perfect, including relations) and the sql generated by doctrine.

I'll be short from now: I have to tables, EVENT and FORM and a 1 to n relation (each event may have multiple forms) so the correct constraint (generated with workbench) is

ALTER TABLE `form` ADD CONSTRAINT `fk_form_event1` FOREIGN KEY (`event_id`) REFERENCES `event` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

doctrine generated statement is:

ALTER TABLE event ADD CONSTRAINT event_id_form_event_id FOREIGN KEY (id) REFERENCES form(event_id);

It's totally reversed and I am sure here is the error. What should I do? It's also correct like this?

2
The SQL generator is old. Don't use it. Write your schemas in YAML and you get to control exactly what SQL is generated. It isn't hard.Amy B
It's not really acceptable that the Doctrine SQL introspection is limited/broken (if that's true) - this is definitely not the case with Propel. YAML is an inferior tool for database design than, say, DBDesigner and just because it's easy enough doesn't mean there isn't a fair point to be made about making it even easier.Raise

2 Answers

0
votes

It it broken, I've wrote the schema manually and it works perfect. I didn't want to do that because it was a very large file, but I've also learned from it!

Thank you guys!

0
votes

To get both visual representation and automatic code generation you can use ORM Designer so you will have everything covered by one tool.