@@ -83,18 +83,25 @@ protected function loadSchema(): void
8383 $ schemaTool = new SchemaTool ($ this ->entityManager );
8484 $ metadata = $ this ->entityManager ->getMetadataFactory ()->getAllMetadata ();
8585
86- $ connection = $ this ->entityManager ->getConnection ();
87- $ schemaManager = $ connection ->createSchemaManager ();
86+ // Create all tables at once to handle dependencies properly
87+ try {
88+ $ schemaTool ->createSchema ($ metadata );
89+ } catch (ToolsException $ e ) {
90+ // If creating all tables at once fails, try to create them one by one
91+ // This is a fallback mechanism
92+ $ connection = $ this ->entityManager ->getConnection ();
93+ $ schemaManager = $ connection ->createSchemaManager ();
8894
89- foreach ($ metadata as $ classMetadata ) {
90- $ tableName = $ classMetadata ->getTableName ();
95+ foreach ($ metadata as $ classMetadata ) {
96+ $ tableName = $ classMetadata ->getTableName ();
9197
92- if (!$ schemaManager ->tablesExist ([$ tableName ])) {
93- try {
94- $ schemaTool ->createSchema ([$ classMetadata ]);
95- } catch (ToolsException $ e ) {
96- // nothing to do
97- echo $ e ->getMessage ();
98+ if (!$ schemaManager ->tablesExist ([$ tableName ])) {
99+ try {
100+ $ schemaTool ->createSchema ([$ classMetadata ]);
101+ } catch (ToolsException $ e ) {
102+ // Log the error but continue with other tables
103+ echo $ e ->getMessage () . PHP_EOL ;
104+ }
98105 }
99106 }
100107 }
0 commit comments