wbh1 / grafana-sqlite-to-postgres

Grafana SQLite to Postgres Database Migrator
MIT License
97 stars 26 forks source link

duplicate key value violates unique constraint #11

Closed maksim77 closed 4 years ago

maksim77 commented 4 years ago

Thank you for the great program!

I'm trying to migrate Grafana (7.0) from sqlite to postgres (12). An error occurs when trying to load the "users" table:

a duplicate key value violates the uniqueness restriction "user_pkey1"

maksim77 commented 4 years ago

Actually, the error is understandable. In the database that was initiated by Grafana, the "user" table contains the "postgres" user. And its id is 1. Accordingly, when trying to insert we have this error

INSERT INTO "user" VALUES(1,0,'admin','admin@localhost','','abac827d5dac0a20087bcae0cdc1kea40f0fa1099b0164c1be0a1aa16004567ce3559ddea5f477de8f5c138ec254cddc1a904e304','6uEodkHqcZhY','QvddX2N7owGQ','',1,1,0,'','2019-01-16 11:28:49','2019-01-16 11:29:42',1,'2020-05-22 10:19:06',0)

wbh1 commented 4 years ago

That's odd.... Normally the postgres user gets created in a separate table just called user (no quotes).

grafana=# select * from user;
   user
----------
 postgres
(1 row)

grafana=# select count(*) from "user";
 count
-------
    93
(1 row)

I will look into it more today.

maksim77 commented 4 years ago

Maybe the reason is the Grafana of the 7.0 version? The release was very recent.

maksim77 commented 4 years ago

I successfully managed to migrate the database using https://github.com/haron/grafana-migrator (many thanks for the link!).

By the way, when running this program, errors of violation of uniqueness also appeared many times, but according to README they must be ignored.