【发布时间】:2019-06-15 13:09:14
【问题描述】:
在我的 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”只是我最近的尝试。删除它也会产生相同的结果。
【问题讨论】:
标签: javascript node.js heroku sequelize.js heroku-postgres