我使用sequelize迁移从我的数据库中的模型中删除了一列,即使迁移成功执行,sequelize仍在尝试查询我的Node.js应用程序中的相同字段 .
这是我正在尝试执行的代码:
db.Alarm.all({ logging: console.log })
.catch(console.log)
这是查询日志输出的一部分( user_id 是已删除的列):
Executing (default): SELECT "id", "driver_id", "dismissed_by", (...), "user_id"
FROM "alarms" AS "Alarm" WHERE "Alarm"."deleted_at" IS NULL;
这是catch输出的一部分:
{ [SequelizeDatabaseError: column "user_id" does not exist]
name: 'SequelizeDatabaseError',
message: 'column "user_id" does not exist',
original:
{ [error: column "user_id" does not exist]
name: 'error',
length: 101,
severity: 'ERROR',
code: '42703',
detail: undefined,
hint: undefined,
position: '257',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_relation.c',
line: '3090',
routine: 'errorMissingColumn',
sql: 'SELECT "id", "driver_id", "dismissed_by", (...), "user_id" FROM "alarms" AS "Alarm" WHERE "Alarm"."deleted_at" IS NULL;' }
我从我的警报模型中删除了user_id字段和belongsTo(用户)关联 . 我的模型对用户的唯一引用是列dismissed_by,可以在上面的输出中看到 . 我've also checked my Alarms table in PostgreSQL and indeed there'没有user_id列,所以我继续've no idea of what' .
Update :此问题似乎只影响外键列 . 我已经能够成功地从模型中添加/删除/重命名其他列,但在重命名列dismissed_by时遇到了同样的问题 .
1 回答
事实证明我错过了User模型中的hasMany关联(对于user_id列) . 当我删除它时,它工作得很好=]