Fix MySQL export incorrect Foreign Key placement for One-to-Many relationships #783
+35
−20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🐛 Bug Fix
The Issue - #749
When exporting to MySQL, the SQL generator always applied the
FOREIGN KEYconstraint to the Start Table (the table where the user started drawing the relationship line).If a user drew a line from a Parent Table (Primary Key) to a Child Table (Foreign Key) and set the cardinality to One-to-Many, the exporter incorrectly tried to add the Foreign Key column to the Parent Table. This resulted in invalid SQL schemas.
The Solution
I updated
src/utils/exportSQL/mysql.jsto check the relationship cardinality during export.r.cardinality === Cardinality.ONE_TO_MANY.ALTER TABLEstatement to the End Table (the "Many" side) instead of the Start Table.How to Test
Users(Parent) andOrders(Child).Usersand connecting toOrders.ALTER TABLE 'Orders' ADD FOREIGN KEY...ALTER TABLE 'Users' ADD FOREIGN KEY...Use Arrow Up and Arrow Down to select a turn, Enter to jump to it, and Escape to return to the chat.