如何在Sequelize中删除Constraint defaultValue

cle*_*ton 0 database-migration node.js sequelize.js sequelize-cli

我正在尝试在 Sequelize 中编写迁移并希望删除 defaultValue 约束。什么是正确的语法?我已经尝试了以下两种方法:

return queryInterface.removeConstraint('Table', 'table_columnName_default')
return queryInterface.removeConstraint('Table', 'columnName_default')
Run Code Online (Sandbox Code Playgroud)

小智 6

你能试试用吗

return queryInterface.changeColumn('Table', 'attributeName', {
    defaultValue: null,
    allowNull: true,
});
Run Code Online (Sandbox Code Playgroud)

http://docs.sequelizejs.com/class/lib/query-interface.js~QueryInterface.html#instance-method-changeColumn

  • 我编辑了上面的答案以添加类型——这是必要的,否则迁移失败。 (3认同)