SequelizeDatabaseError: column "id_strain" of relation "strain" is already an identity column

SequelizeDatabaseError: column "id_strain" of relation "strain" is already an identity column

我正在使用 sequelize 和 sequelize auto 使用自定义迁移脚本将 SQL 服务器数据库迁移到 postgres。所以当我 运行 迁移时我得到一个错误

Error: SequelizeDatabaseError: column "id_strain" of relation "strain" is already an identity column

迁移文件是

module.exports = {
    up: async (queryInterface, Sequelize, transaction) => {
        try {
            // Generate Schema if dont exist
            await queryInterface.sequelize.query(
                'CREATE SCHEMA IF NOT EXISTS "base";',
                {
                    transaction,
                }
            )

            // Create table
            await queryInterface.createTable(
                { schema: 'base', tableName: 'strain' },
                {
                    id_strain: {
                        type: Sequelize.INTEGER,
                        allowNull: false,
                        primaryKey: true,
                        autoIncrementIdentity: true,
                    },
                },
                { transaction: transaction }
            )

            // Alter table queries
            await queryInterface.sequelize.query(
                'ALTER TABLE "base"."strain" ALTER COLUMN id_strain ADD GENERATED BY DEFAULT AS IDENTITY (START WITH 1000 INCREMENT BY 1)',
                {
                    transaction,
                }
            )
        } catch (e) {
            console.log(e)
            throw Error(e)
        }
    },

    down: async (queryInterface, Sequelize) => {
        /**
         * Add reverting commands here.
         *
         **/
        await queryInterface.dropTable({
            schema: 'base',
            tableName: 'strain',
        })
    },
}

已由 Bee-Riii 的 comment.thanks

修复