续集播种机:意外的标识符错误,没有堆栈跟踪进一步解释它



我在使用Sequelize时遇到了问题,使用自动增量键为Postgres运行sequelize:seed破坏了向该表添加新项目的能力。Sequelize 不会自动将模型与表中的最新 id 同步,因此在添加种子数据后我遇到了重复键错误。

我试图使用我在这里找到的关于在种子文件运行后重新同步串行的一些建议来修复它,但我收到一个Unexpected Identifier错误,没有进一步的解释。

这是我的代码 - 谁能说出出了什么问题?我的 linter 没有抛出任何错误,所以我认为这不是标准的语法错误:

'use strict';
const db = require('../models');
module.exports = {
up: async (queryInterface, Sequelize) => {
/*
Add altering commands here.
Return a promise to correctly handle asynchronicity.
Example:
return queryInterface.bulkInsert('People', [{
name: 'John Doe',
isBetaMember: false
}], {});
*/
return await queryInterface
.bulkInsert('user_podcasts', [
{
id: 1,
userId: 1,
podcastId: '88b15eefe35d42c58bca9c5e17080661',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString()
},
{
id: 2,
userId: 1,
podcastId: '7f519d33692246a98688a1415c3c591c',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString()
},
{
id: 3,
userId: 2,
podcastId: '7f519d33692246a98688a1415c3c591c',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString()
},
{
id: 4,
userId: 2,
podcastId: 'd9604d45a8494577bec068df875fb69d',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString()
}
])
.then(async () =>
db.query(
`ALTER SEQUENCE "${
model.user_podcasts
}_id_seq" RESTART WITH ${(await model.count()) + 1}`
)
)
.catch(error => {
if (error.message.indexOf('already exists') > -1) return;
console.log(error);
});
},
down: (queryInterface, Sequelize) => {
/*
Add reverting commands here.
Return a promise to correctly handle asynchronicity.
Example:
return queryInterface.bulkDelete('People', null, {});
*/
}
};

使用此命令获取错误堆栈跟踪。请注意 --debug选项。

sequelize-cli db:migrate --debug

如果您尚未安装 sequelize-cli,请使用以下命令进行安装。

npm install sequelize-cli 

如果需要,您可以使用-g选项全局安装它。