Bidoubiwa
Bidoubiwa

Reputation: 960

SQL migrations. Keeping old ID is not working

I'm migrating an old database to a new database (mysql => postgres).

For simplicity i kept the old IDs so id did something like that in knex

knex("my_table").withSchema("mySchema").insert({ 
         id : old[i].id,
         info : old[i].info 
     })

It appears doing that cancels postgres auto_inc on ID and thus when i try to insert later like that :

knex("my_table").withSchema("mySchema").insert({ 
             info : "information"
         })

It will automaticly attribute it to ID : 1. Even if it already exist because of the migration.

My question is : Can i still keep the old id ?

Upvotes: 0

Views: 44

Answers (1)

AmeyaN99
AmeyaN99

Reputation: 172

please try altering the sequence assigned to the my_table.id column for auto-increment.

alter it such that it will start from max(old_id)+1

http://www.postgresqltutorial.com/postgresql-serial/

https://www.postgresql.org/docs/9.1/static/sql-altersequence.html

Upvotes: 2

Related Questions