gpt4 book ai didi

javascript - SequelizeDatabaseError : dropping non-existent ENUM types, 但它们确实存在

转载 作者:行者123 更新时间:2023-12-03 22:19:57 25 4
gpt4 key购买 nike

当尝试在我的 heroku-postgres 数据库中撤消 sequelize 迁移时,我得到 SequelizeDatabaseError ,因为 ENUM 类型应该不存在。

我有几个带有 ENUM 数据类型的表/模型。在向下迁移中,我尝试删除表,然后也删除表的关联枚举数据类型。到目前为止,似乎只有一种迁移适用于两个方向。

我尝试手动删除每种类型,然后全部迁移,然后全部撤消,但在相同的模型上总是失败,说 ENUM 类型不存在(当它们显然是在向上迁移中创建时)。

这是一个向下迁移失败的模型。

'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('PatientContacts', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
phoneHome: {
type: Sequelize.STRING,
allowNull: true,
},
phoneWork: {
type: Sequelize.STRING,
allowNull: true,
},
phoneMobile: {
type: Sequelize.STRING,
allowNull: false,
},
phonePreferred: {
type: Sequelize.ENUM,
values: ['Home','Work','Mobile', null]
},
smsNotifications: {
type: Sequelize.ENUM,
values: [true, false, null]
},
email: {
type: Sequelize.STRING,
allowNull: true,
},
emailConsent: {
type: Sequelize.ENUM,
values: [true, false, null]
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('PatientContacts')
.then(() => queryInterface.sequelize.query('DROP TYPE "public"."enum_PatientContacts_emailConsent;"'))
.then(() => queryInterface.sequelize.query('DROP TYPE "public"."enum_PatientContacts_phonePreferred;"'))
.then(() => queryInterface.sequelize.query('DROP TYPE "public"."enum_PatientContacts_smsNotifications;"'))
.catch(err => {
console.log(err);
throw new Error(err);
})
}
};

我希望向下迁移在回调中执行原始查询。然而,错误如上所述:
Error: SequelizeDatabaseError: type "public.enum_PatientContacts_emailConsent;" does not exist
at queryInterface.dropTable.then.then.then.catch.err (/app/migrations/20181213023202-create-PatientContact.js:56:13)
at tryCatcher (/app/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/app/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/app/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/app/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/app/node_modules/bluebird/js/release/promise.js:690:18)
at _drainQueueStep (/app/node_modules/bluebird/js/release/async.js:138:12)
at _drainQueue (/app/node_modules/bluebird/js/release/async.js:131:9)
at Async._drainQueues (/app/node_modules/bluebird/js/release/async.js:147:5)
at Immediate.Async.drainQueues [as _onImmediate] (/app/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:693:18)
at tryOnImmediate (timers.js:664:5)
at processImmediate (timers.js:646:5)

我应该提到,在类型名称前加上“public”只是我最近的尝试。删除它也会产生相同的结果。

最佳答案

我很失望我在这个问题上被困了几个小时。

结束原始查询的分号应该出现在结束类型名称的双引号之后,但在结束整个 sql 查询本身的单引号之前。

关于javascript - SequelizeDatabaseError : dropping non-existent ENUM types, 但它们确实存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54301911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com