Skip to content

Conversation

@Ankit-bit-cyber
Copy link

🐛 Bug Fix

The Issue - #749

When exporting to MySQL, the SQL generator always applied the FOREIGN KEY constraint 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.js to check the relationship cardinality during export.

  • Logic now detects if r.cardinality === Cardinality.ONE_TO_MANY.
  • If true, it dynamically swaps the target, applying the ALTER TABLE statement to the End Table (the "Many" side) instead of the Start Table.
  • This ensures valid SQL generation regardless of which direction the relationship line was drawn.

How to Test

  1. Open DrawDB editor.
  2. Create two tables: Users (Parent) and Orders (Child).
  3. Draw a relationship starting from Users and connecting to Orders.
  4. Set the relationship cardinality to One-to-Many.
  5. Click File > Export as > MySQL.
  6. Verify the generated SQL:
    • Expected: ALTER TABLE 'Orders' ADD FOREIGN KEY...
    • Previous (Bug): 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.

@vercel
Copy link

vercel bot commented Dec 2, 2025

@Ankit-bit-cyber is attempting to deploy a commit to the dottle's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant