Manage primary keys
When you set a foreign key to another table, you need to specify the primary key of the referenced table. This is required to create the table relationship. This also automatically sets a primary key if the referenced table did not already have one.
If necessary, you can manually set and remove primary keys for each table in a generator.
Set a primary key
You can set the primary key for any table regardless of the synthetic data use case (single-table, two-table, or multi-table).
Steps
- On the Data configuration page, click the Primary key drop-down for a table.
- Select the primary key column for the table.
- (Optional) Repeat for all tables.
Remove a primary key
To remove a primary key, hover over a table in the Primary key column and click the button.
![MOSTLY AI - Remove primary key](/docs/_next/image?url=%2Fdocs%2Fdocimages%2Fgenerators%2Fset-table-relationships%2Fremove-pk-01-hover-over-table-click-x.webp&w=1920&q=75)
If a foreign key references the primary key you want to remove, you will get a warning that this will break the existing relationship.
![MOSTLY AI - Cannot remove primary key error](/docs/_next/image?url=%2Fdocs%2Fdocimages%2Fgenerators%2Fset-table-relationships%2Fremove-pk-02-warning-relationship-break.webp&w=1920&q=75)