@@ -83,18 +83,25 @@ protected function loadSchema(): void
83
83
$ schemaTool = new SchemaTool ($ this ->entityManager );
84
84
$ metadata = $ this ->entityManager ->getMetadataFactory ()->getAllMetadata ();
85
85
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 ();
88
94
89
- foreach ($ metadata as $ classMetadata ) {
90
- $ tableName = $ classMetadata ->getTableName ();
95
+ foreach ($ metadata as $ classMetadata ) {
96
+ $ tableName = $ classMetadata ->getTableName ();
91
97
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
+ }
98
105
}
99
106
}
100
107
}
0 commit comments