node.js Sequelize 已弃用的错误消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46608382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:31:35  来源:igfitidea点击:

Sequelize Deprecated Error Message

node.jssequelize.js

提问by JK36

I'm very new to Node and I'm getting my head around how ORM and Sequelize works. I've been on the Sequelize website and copied the connection string and altered it to work with my database. When I execute the file, it seems to execute OK creating the table in my database however I get the error "String based operators are now deprecated.Please use Symbol based operators for better security ....node_modules/sequelize/lib/sequelize.js:236:13" I understand why the operators have been deprecated, however as I've installed this as a new package and used the connection string from the documentation, thus avoiding using any illegal operators am I right in assuming this error message is for info only and not reflected in the code I have just used.

我对 Node 非常陌生,我正在了解 ORM 和 Sequelize 的工作原理。我一直在 Sequelize 网站上复制连接字符串并将其更改为与我的数据库一起使用。当我执行文件时,它似乎在我的数据库中创建表执行正常,但是我收到错误“基于字符串的运算符现在已弃用。请使用基于符号的运算符以获得更好的安全性....node_modules/sequelize/lib/sequelize。 js:236:13" 我理解为什么不推荐使用运算符,但是因为我已将其安装为新软件包并使用文档中的连接字符串,从而避免使用任何非法运算符,我假设此错误消息是正确的仅供参考,并未反映在我刚刚使用的代码中。

I include my for app file that is bringing up the error, is it the password that maybe causing this.

我包含了导致错误的 for app 文件,是不是可能导致此错误的密码。

const express = require('express');
const app = express();

const Sequelize = require('sequelize');

const db = new Sequelize('myDBName', 'mYuSeRnAmE', 'mYpAsSw!ORd$', {
host: 'mySqlserverName',
  dialect: 'mssql',

  pool: {
    max: 5,
    min: 0,
    idle: 10000
  },

});


var Article = db.define('Article', {
    title: Sequelize.STRING,
    body: Sequelize.TEXT
});

db.sync();

module.exports = app;

**** Edit ****

**** 编辑 ****

I've figured it out, I'll leave this answer up just incase someone else runs into the problem. You need to include { operatorsAliases: false } to get rid of the error message in the connection.

我已经想通了,我会留下这个答案,以防万一其他人遇到问题。您需要包含 { operatorsAliases: false } 以消除连接中的错误消息。

回答by user3139574

These were the best explanations that I found for this deprecation warning:

这些是我为这个弃用警告找到的最好的解释:

https://github.com/sequelize/sequelize/issues/8417

https://github.com/sequelize/sequelize/issues/8417

http://docs.sequelizejs.com/manual/tutorial/querying.html#operators-aliases

http://docs.sequelizejs.com/manual/tutorial/querying.html#operators-aliases

Adding "operatorsAliases: false" did override the warning message in my application.

添加“operatorsAliases: false”确实覆盖了我的应用程序中的警告消息。

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

Note: as of [email protected] I started receiving "Invalid value" errors from Sequelize. I relented and used the following code to enable symbol operators:

注意:从 [email protected] 开始,我开始收到来自 Sequelize 的“无效值”错误。我软化并使用以下代码来启用符号运算符:

const Sequelize = require('sequelize')
const Op = Sequelize.Op
const sequelize = new Sequelize(
  DB_NAME,
  USERNAME, 
  PASSWORD,
  {
    host: HOSTNAME,
    dialect: 'mysql',
    logging: false,
    freezeTableName: true,
    operatorsAliases: {
      $and: Op.and,
      $or: Op.or,
      $eq: Op.eq,
      $gt: Op.gt,
      $lt: Op.lt,
      $lte: Op.lte,
      $like: Op.like
    }
  }
)

回答by BartusZak

Updating to version:

更新到版本:

"sequelize": "^5.8.6"

and removing operatorsAliasesparam from

operatorsAliases从中删除参数

new Sequelize()

removed depreciation warning

移除折旧警告

回答by Frank HN

const sequelize = new Sequelize({
  username: process.env.DBUSERNAME,
  host: process.env.DBHOST,
  database: process.env.DBNAME,
  password: process.env.DBPASSWORD,
  dialect: 'postgres',
  define: {
    timestamps: false,
  },
  operatorsAliases: false,
  pool: {
    max: 5,
    min: 0,
    idle: 10000
  },

});