jeudi 29 janvier 2015

Broken foreign keys on MySQLWorkbench forward engineered db. Table creation order matters?


I recently generated a forward engineered database script in MySQLWorkbench. The script wouldn't run, and by pasting chunks in the shell interpreter, I determined that a particular table was causing the trouble. show engine innodb status said:



150129 17:46:48 Error in foreign key constraint of table dbname/problematic_table: blah blah blah FOREIGN KEY (`your_foreign_key`) REFERENCES `table_not_yet_created`(`primary-key`)


In effect, the table table_not_yet_created hasn't been created yet. I then can't drop problematic_table or recreate it as per similar innodb foreign key questions and get a corrupted db. My two-part question:



  1. Having to manually edit the file afterwards is annoying. Am I doing something wrong such that the sql script that workbench spits out creates the tables in the wrong order?

  2. If I can't get workbench to create the tables in order, can I just get MySQL to trust me on the database architecture and not complain about inconsistencies until I'm done creating all my tables?





Aucun commentaire:

Enregistrer un commentaire