Cannot drop primary key - primary key belongs to a constraint

121 views
Skip to first unread message

Michael Earl

unread,
May 28, 2022, 1:51:20 PM5/28/22
to H2 Database
Hello All,

I'm trying to add a column to a primary key.
I have dropped all constraints that I can see that are related to the table but I still get this error: Database exception performing upgrade: Index "PRIMARY_KEY_2C0" belongs to a constraint;

I'm looked in the INFORMATION_SCHEMA.CONSTRAINTS and I don't see any references to that index.

Also, when I visualize the table relationships using DataGrip, there are no other related tables.

How can I find out what to drop in order to drop the primary key so that I can recreate it?

Thank you,
Mike.

Evgenij Ryazanov

unread,
May 28, 2022, 11:01:49 PM5/28/22
to H2 Database
Hello.

There is no such table as INFORMATION_SCHEMA.CONSTRAINTS in supported version of H2, unless legacy information schema was enabled explicitly or due to remote connection from an old driver.

Only outdated unsupported versions of H2 have such table. They all have various bugs with constraints.
Referential (foreign key) constraints in them didn't require an existing primary key or unique constraint on referenced columns in the referenced table (in modern versions of H2 such constraint is required).
They only need an unique index on them in the referenced table.

You need to check referential constraints declared in other tables, most likely one (or some) of them references your old primary key column. You need to drop it too.
Reply all
Reply to author
Forward
0 new messages