Is the database configurable to support constraints with same name for different tables?

44 views
Skip to first unread message

Gino Marckx

unread,
Apr 9, 2025, 1:14:08 AMApr 9
to H2 Database
I use flywaydb for a production system that has many migration scripts. Every table that has a foreign key to table A has it named 'FK_A'. This works for my postgres database (the constraint name is unique within the table), but not when I create automated tests which use the H2 database.

Is there a way to configure H2 to allow for the same foreign key constraint names, as long as they are specified on different tables?

If not, I will have to recreate the migration scripts, and manually update my production database. If anyone has an easy way to do this, I'm all ears.

Kind regards
Gino

Evgenij Ryazanov

unread,
Apr 9, 2025, 6:33:05 AMApr 9
to H2 Database
Hello!

In the SQL Standard names of constraints must be unique within a schema and H2 is implemented in that way. Some data definition commands from the Standard and INFORMATION_SCHEMA depend on this uniqueness. So no, it isn't possible and it shouldn't be possible to have such configuration option, it is too complex by itself and it will break some important features, such as possibility to read database metadata.

Gino Marckx

unread,
Apr 9, 2025, 3:23:29 PMApr 9
to H2 Database
Thanks for the info!

I was able to fix it quickly by adding a migration to rename the constraints and adding a baseline so the individual migrations are skipped for my tests.
Reply all
Reply to author
Forward
0 new messages