Foreign Key Configuration and ER Diagram
Who this is for
For users who need to define table relationships and want to view overall data structure visually.
What this solves
You can clarify foreign key constraints and cascade rules during the design phase, avoiding data integrity issues after launch; the ER diagram helps teams quickly understand table relationships.
Prerequisites
- The current table has at least one field.
- The target table and fields for association are already identified.
Steps
- Switch to the
Foreign Key Configurationtab in the table configuration area. Result: enter the foreign key management panel. - Click
Add Foreign Key. Result: a foreign key editing row expands. - Fill in
Foreign Key Name(optional, system can auto-generate), selectField(current table field),Related Table, andRelated Field. Result: the foreign key relationship is established. - Set
Update RuleandDelete Ruleas needed (such as CASCADE, SET NULL, RESTRICT, etc.). Result: cascade behavior is defined. - Repeat the above steps to add more foreign keys. Result: the current table can be associated with multiple tables.
- Click
View ER Diagram. Result: the system opens an ER diagram popup, rendering all table nodes and relationship lines based on React Flow. - In the ER diagram, drag nodes to adjust layout, zoom with scroll wheel, and click relationship lines to view foreign key details. Result: the team can intuitively understand table relationships.
Done when
- Foreign key configuration panel lists all target foreign keys, with correct fields, related tables, and related fields.
- DDL on the right already contains
FOREIGN KEYstatements. - ER diagram correctly shows relationship lines between current table and associated tables.
- Update/delete rules match business expectations.
Common pitfalls
- When foreign key field and related field types are incompatible, generated DDL may fail on the target database. Confirm type matching in advance.
- If the related table does not exist in the current workspace, the ER diagram may only show the node without its field details.
- Leaving foreign key name empty causes auto-generation by the system; if you have special naming conventions, manual entry is recommended.
- Not all databases support all cascade rules (e.g., SET NULL requires the field to be nullable). Confirm target database support before selecting.