如何更改postgresql获取id的下一个值时将使用的序列?

时间:2017-03-14 14:57:16

标签: postgresql sequelize.js

我有2个字段id的表格,由sequelize自动创建。

table1
id integer not null default nextval('table1_d_seq'::regclass)

table2
id integer not null default nextval('table2_d_seq'::regclass)

我可以使用修饰符sequelize调整idtable2创建nextval('table1_d_seq'::regclass)字段吗?

1 个答案:

答案 0 :(得分:0)

您可以创建一个迁移文件,该文件将更改指定的列,并通过sequelize.query()

提供的queryInterface方法设置其默认值
module.exports = {
    up: function (queryInterface, Sequelize){

        return queryInterface.sequelize.query(
            "ALTER TABLE table2 ALTER COLUMN id SET DEFAULT nextval('table1_d_seq'::regclass)"
        );

    },

    down: function (queryInterface, Sequelize) {

    }
}