Problem
A multi-table SQL export writes tables in whatever order the tree lists them. Importing that file into a database with foreign keys enabled fails on the first child row whose parent is not there yet. The Disable foreign key checks option papers over it, but it needs a privilege on PostgreSQL and it is off for engines that ignore it.
Proposed solution
- Topologically sort tables by foreign key dependency before writing, parents first.
- On a cycle, fall back to the current order and say so in the export summary rather than writing something that cannot import.
- Keep the existing behaviour of adding foreign keys with
ALTER TABLE ... ADD CONSTRAINT after the data, so the two paths agree.
Alternatives considered
Reorder the file by hand, or disable foreign key checks and hope.
Related database type
PostgreSQL
Problem
A multi-table SQL export writes tables in whatever order the tree lists them. Importing that file into a database with foreign keys enabled fails on the first child row whose parent is not there yet. The Disable foreign key checks option papers over it, but it needs a privilege on PostgreSQL and it is off for engines that ignore it.
Proposed solution
ALTER TABLE ... ADD CONSTRAINTafter the data, so the two paths agree.Alternatives considered
Reorder the file by hand, or disable foreign key checks and hope.
Related database type
PostgreSQL