[英]Sequelize fields must be specified through options.field error
所以我創建了一個表並在稍后修改它以添加一個外鍵。 我跟着這個https://stackoverflow.com/a/47428160/12539780但它給了我一個錯誤說
“錯誤:必須通過 options.fields 指定字段”
我正在使用 sequelize ^6.6.5 並且我的節點版本是 14.17.6 我的代碼在下面提供
module.exports = {
up: async (queryInterface, Sequelize) =>
Promise.all([
await queryInterface.addColumn('bonus_transactions', 'wallet_id', {
type: Sequelize.INTEGER.UNSIGNED,
allowNull: false,
after: 'order_id'
}),
await queryInterface.addConstraint('bonus_transactions', ['wallet_id'], {
type: 'FOREIGN KEY',
name: 'FK_bonus_transactions_wallet_id',
references: {
table: 'wallets',
field: 'id'
},
onDelete: 'CASCADE'
})
]),
down: queryInterface => queryInterface.removeColumn('bonus_transactions', 'wallet_id')
這可能是因為續集版本? 我搜索了 v6 文檔,似乎沒有任何與此類似的實現。
addConstaint
中的字段應在fields
選項中指示,如下所示:
queryInterface.addConstraint('bonus_transactions',{
type: 'FOREIGN KEY',
name: 'FK_bonus_transactions_wallet_id',
fields: ['wallet_id'],
references: {
table: 'wallets',
field: 'id'
},
onDelete: 'CASCADE'
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.