sql迁移保留旧身份证不起作用

4sup72z8  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(258)

我正在将一个旧数据库迁移到一个新数据库(mysql=>postgres)。
为了简单起见,我保留了旧的id,所以id在knex中做了类似的事情

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

这样做似乎取消了postgres auto_inc on id,因此当我稍后尝试插入时,如下所示:

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

它将自动将其属性为id:1。即使它已经因为迁移而存在。
我的问题是:我还能保留旧身份证吗?

nqwrtyyt

nqwrtyyt1#

请尝试更改分配给myu table.id列的顺序,以便自动递增。
更改它,使其从max(旧的\u id)+1开始
http://www.postgresqltutorial.com/postgresql-serial/
https://www.postgresql.org/docs/9.1/static/sql-altersequence.html

相关问题