gpt4 book ai didi

node.js - Sequelize .create 没有为我的模型生成内容

转载 作者:行者123 更新时间:2023-11-29 14:09:18 27 4
gpt4 key购买 nike

我到处找这个问题,但没找到。我正在为 Postgres 使用 Sequelize,并且正在尝试向模型添加内容。它不会抛出任何错误,除了一个警告,指出基于字符串的操作已被弃用,但这不是一个操作。

sequelize deprecated 基于字符串的运算符现已弃用。请使用基于符号的运算符以获得更好的安全性,阅读更多信息 http://docs.sequelizejs.com/manual/tutorial/querying.html#operators

这是我的模型和 .create 代码

const Sequelize = require('sequelize');
const sequelizeInstance = new Sequelize('journal_entries', 'KupidoExportLLC',
{
dialect: 'postgres'
});



module.exports = function(sequelizeInstance, DataTypes){
const Entries = sequelizeInstance.define('entries', {
user: Sequelize.STRING,
title: Sequelize.STRING,
content: Sequelize.TEXT
})

Entries.sync().then(function(){
Entries.create({
user: 'I need to get this to work',
title: 'Ill be really happy when this does work',
content: 'It will work this time'
})
});



return Entries;

}

这是我的命令行显示的内容

sequelize deprecated 基于字符串的运算符现已弃用。请使用基于符号的运算符以获得更好的安全性,阅读更多信息 http://docs.sequelizejs.com/manual/tutorial/querying.html#operators node_modules/sequelize/lib/sequelize.js:242:13

当我去看我的 table 时,它是空的

journal_entries=# SELECT * FROM entries;
id | user | title | content | createdAt | updatedAt
----+------+-------+---------+-----------+-----------
(0 rows)

我不知道它还能是什么

最佳答案

您需要关闭警告。

在您的 config.JSON 文件中或(如果您已在同一文件中初始化连接)关闭警告,如下所示:

IN Config.JSON

{
"development": {
"username": "root",
"password": "12345",
"database": "fasttrack",
"host": "localhost",
"dialect": "mysql",
"define": {
"timestamps": false
},
"operatorsAliases": false
},
"test": {
"username": "root",
"password": "12345",
"database": "fasttrack",
"host": "localhost",
"dialect": "mysql",
"define": {
"timestamps": false
},
"operatorsAliases": false
},
"production": {
"username": "root",
"password": "12345",
"database": "fasttrack",
"host": "localhost",
"dialect": "mysql",
"define": {
"timestamps": false
},
"operatorsAliases": false
}
}

连接的内联声明

const sequelize = new Sequelize(config.database, config.username, config.password, { 主机:config.host, 方言:config.dialect, 水池: { 最大:5, 分钟:0, 闲置:10000 }, 记录:假, freezeTableName:是的, operatorsAliases: false});

关于node.js - Sequelize .create 没有为我的模型生成内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48993216/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com