0
我已經使用續集遷移從數據庫中的模型中刪除了一列,即使遷移執行成功,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,可以在上面的輸出中看到。我還檢查了PostgreSQL中的Alarms表,並且確實沒有user_id列,所以我不知道發生了什麼。
更新:此問題似乎隻影響外鍵列。我已經能夠成功添加/刪除/重新命名模型中的其他列,但在重命名dismissed_by列時也遇到同樣的問題。
也許在遷移前後可以使用模型。需要更多的信息才能幫到 –
@DanRocha這個問題是我忘記在其中一個模型中刪除的關聯 –