Failed to Migrate H2 to Postgres 12.7

Hi,

I tried to migrate from H2 to Postgres. Getting following error.
Command failed with exception: ERROR: insert or update on table "metabase_table" violates foreign key constraint "fk_table_ref_database_id" Detail: Key (db_id)=(102) is not present in table "metabase_database".

Version Details:
Metabase : Metabase v0.41.5
Postgres : 12.7 (running in docker conatiner)
Java : openjdk 11.0.13 2021-10-19

Steps I have performed:

  1. backup of metabase.db.mv.db.
  2. created user and database. in postgres
  3. java -jar metabase.jar load-from-h2 metabase.db

Hi @sujit.patel
It seems like you have row(s) in metabase_table with where db_id = 102, but you don't actually have that database in metabase_database.

I have absolutely no idea how you ended up in this situation, but likely because your H2 database is very old and this problem occurred before 0.36

You will need to remove those rows in metabase_table with something like:
DELETE from metabase_table where db_id=102;

Hi @flamber

you mean i have to delete this record from H2 database?
If yes, can you pls share the steps to connect to h2 database?

@sujit.patel You should be able to do something like this - haven't tested.
Create a file called cleanup.sql and add the queries you want to execute (like the DELETE-statement)
This run this:

java -cp metabase.jar org.h2.tools.RunScript -script cleanup.sql -url jdbc:h2:metabase.db
1 Like

Thanks @flamber.

This resolved my issue.
I used this command.

java -cp metabase.jar org.h2.tools.RunScript -script cleanup.sql -url jdbc:h2:/apps/metabase.db