【问题标题】:Sequelize V5 - BOOLEAN data type not supported when creating a ModelSequelize V5 - 创建模型时不支持 BOOLEAN 数据类型
【发布时间】:2020-05-08 05:44:57
【问题描述】:

我最近将"sequelize": "^5.21.3" 安装到我的新节点项目中。我也在使用“sequelize-auto-migrations”来同步数据库。(https://www.npmjs.com/package/sequelize-auto-migrations)

然后我用布尔类型字段创建我的第一个模型 [用户]。

module.exports = function (sequelize, DataTypes) {
    var User = sequelize.define('user', {
        EpfNo: {
            type: Sequelize.INTEGER,
            autoIncrement: false,
            allowNull: false,
            primaryKey: true
        },
        Title: {
            type: Sequelize.STRING(10)
        },
        EmailAddress: {
            type: Sequelize.STRING(100)
        },
        ContactNo: {
            type: Sequelize.STRING(20)
        },
        IsValidUser:{
            type:Sequelize.BOOLEAN
        },
        IsActive: {
            type:Sequelize.BOOLEAN
        }
    })

但是当我尝试运行迁移时,它会显示以下错误消息。

[#0] 执行:createTable (节点:16296)[SEQUELIZE0004] DeprecationWarning:布尔值已传递给 options.operatorsAliases。这是一个无操作 v5 并且应该被删除。

请帮忙!

【问题讨论】:

标签: node.js sequelize.js


【解决方案1】:

我认为您需要在续集连接中将“operatorsAliases”作为 false 传递,如下所示 -

const Sequelize = require('sequelize')
const sequelize = new Sequelize(
  DB_NAME,
  USERNAME, 
  PASSWORD,
  {
    host: HOSTNAME,
    dialect: 'mysql',
    logging: false,
    freezeTableName: true,
    operatorsAliases: false
  }
)

也根据你的代码 -

module.exports = function (sequelize, DataTypes) {

您使用了较小的后续集,但在归档定义中您使用了 资本

type:Sequelize.BOOLEAN

这有帮助。

【讨论】:

    猜你喜欢
    • 2014-01-05
    • 1970-01-01
    • 1970-01-01
    • 2018-07-18
    • 2019-08-10
    • 2020-02-03
    • 1970-01-01
    • 2019-12-12
    • 2020-02-28
    相关资源
    最近更新 更多