Postgresql 在sequelize上运行迁移时出错
Postgresql 在sequelize上运行迁移时出错,postgresql,docker,sequelize.js,Postgresql,Docker,Sequelize.js,“严格使用”; module.exports={ up:(查询接口,续集)=>{ 回报你的承诺([ queryInterface.addColumn('Posts','userAccountId',则{ 类型:Sequelize.INTEGER, }), queryInterface.addColumn('Posts','postTopicId'{ 类型:Sequelize.INTEGER, }), queryInterface.addConstraint('Posts',['userAccou
“严格使用”;
module.exports={
up:(查询接口,续集)=>{
回报你的承诺([
queryInterface.addColumn('Posts','userAccountId',则{
类型:Sequelize.INTEGER,
}),
queryInterface.addColumn('Posts','postTopicId'{
类型:Sequelize.INTEGER,
}),
queryInterface.addConstraint('Posts',['userAccountId']{
键入:“外键”,
名称:“userAccountId”,
参考资料:{
表:“用户帐户”,
字段:“id”,
},
onDelete:“无操作”,
onUpdate:“无操作”,
}),
queryInterface.addConstraint('Posts',['postTopicId']{
键入:“外键”,
名称:“postTopicId”,
参考资料:{
表:'PostTopics',
字段:“id”,
},
onDelete:“无操作”,
onUpdate:“无操作”,
}),
]);
},
向下:(查询接口,续集)=>{
回报你的承诺([
queryInterface.removeColumn('Posts','userAccountId'),
queryInterface.removeColumn('Posts','postTopicId'),
queryInterface.removeConstraint('Posts','userAccountId'),
queryInterface.removeConstraint('Posts','postTopicId'),
]);
},
};代码>在执行修改结构并相互依赖的查询时,不应使用Promise.all
<代码>承诺。所有
不保证原始执行顺序查询。使用事务和顺序执行:
return queryInterface.sequelize.transaction(async transaction => {
await queryInterface.addColumn('Posts', 'userAccountId', {
type: Sequelize.INTEGER,
}, { transaction })
await queryInterface.addColumn('Posts', 'postTopicId', {
type: Sequelize.INTEGER,
}, { transaction })
await queryInterface.addConstraint('Posts', ['userAccountId'], {
type: 'foreign key',
name: 'userAccountId',
references: {
table: 'UserAccounts',
field: 'id',
},
onDelete: 'no action',
onUpdate: 'no action',
}, { transaction })
await queryInterface.addConstraint('Posts', ['postTopicId'], {
type: 'foreign key',
name: 'postTopicId',
references: {
table: 'PostTopics',
field: 'id',
},
onDelete: 'no action',
onUpdate: 'no action',
}, { transaction })
});
在执行修改结构并相互依赖的查询时,不应使用
Promise.all
<代码>承诺。所有不保证原始执行顺序查询。使用事务和顺序执行:
return queryInterface.sequelize.transaction(async transaction => {
await queryInterface.addColumn('Posts', 'userAccountId', {
type: Sequelize.INTEGER,
}, { transaction })
await queryInterface.addColumn('Posts', 'postTopicId', {
type: Sequelize.INTEGER,
}, { transaction })
await queryInterface.addConstraint('Posts', ['userAccountId'], {
type: 'foreign key',
name: 'userAccountId',
references: {
table: 'UserAccounts',
field: 'id',
},
onDelete: 'no action',
onUpdate: 'no action',
}, { transaction })
await queryInterface.addConstraint('Posts', ['postTopicId'], {
type: 'foreign key',
name: 'postTopicId',
references: {
table: 'PostTopics',
field: 'id',
},
onDelete: 'no action',
onUpdate: 'no action',
}, { transaction })
});