gpt4 book ai didi

node.js - 使用 sequelize postgres 时出现语法错误

转载 作者:行者123 更新时间:2023-12-03 22:42:53 25 4
gpt4 key购买 nike

sequelize: 1.7.0
pg: 2.11.1
posgreSql: 9.3 (pg server on my pc)

我有使用以下配置的应用程序:
db: 'mysql://user:pass@localhost/dbname'

它适用于 sequelizemysql方言。
当我将其更改为:
db: 'postgres://user:pass@localhost/dbname'

和方言 postgres并尝试 sequelize.sync()我收到以下错误:
{
"message":"syntax error at or near \"(\"",
"name":"error",
"stack":"error: syntax error at or near \"(\"\n at Connection.parseE (/Users/me/Desktop/node/myapp/node_modules/pg/lib/connection.js:561:11)\n at Connection.parseMessage (/Users/me/Desktop/node/myapp/node_modules/pg/lib/connection.js:390:17)\n at [object Object].<anonymous> (/Users/me/Desktop/node/myapp/node_modules/pg/lib/connection.js:92:20)\n at EventEmitter.emit (events.js:95:17)\n at Socket.<anonymous> (_stream_readable.js:746:14)\n at EventEmitter.emit (events.js:92:17)\n at emitReadable_ (_stream_readable.js:408:10)\n at emitReadable (_stream_readable.js:404:5)\n---------------------------------------------\n at module.exports.CustomEventEmitter.failure.CustomEventEmitter.fail.CustomEventEmitter.error (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/emitters/custom-event-emitter.js:93:10)\n at exec (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/query-chainer.js:92:14)\n at onError (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/query-chainer.js:72:11)\n at EventEmitter.emit (events.js:95:17)\n at module.exports.CustomEventEmitter.emit (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/emitters/custom-event-emitter.js:61:33)\n at [object Object].<anonymous> (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/emitters/custom-event-emitter.js:131:17)\n---------------------------------------------\n at module.exports.CustomEventEmitter.failure.CustomEventEmitter.fail.CustomEventEmitter.error (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/emitters/custom-event-emitter.js:93:10)\n at exec (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/query-chainer.js:92:14)\n at onError (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/query-chainer.js:72:11)\n at EventEmitter.emit (events.js:95:17)\n at module.exports.CustomEventEmitter.emit (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/emitters/custom-event-emitter.js:61:33)\n at [object Object].<anonymous> (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/emitters/custom-event-emitter.js:131:17)",
"code":"42601"
},
"msg":"uncaughtException",
"time":"2014-03-31T14:17:29.496Z",
"v":0
}

我做错了什么?

在我创建 dbname 之前pg 中的数据库出现错误 missing database所以我猜 sequelize 连接到 pg 但它会在 pgsql 代码中产生一些语法错误?

问题是在模型模式中我有 Sequelize.INTEGER(11) - 而 postgres 不允许将 11 作为 INTEGER 的大小传递 - 这将在 Sequelize 的 2.x.x 版本中解决(您可以找到与此问题相对应的问题在 Sequelize github repo 上)。

最佳答案

Sequelize 和 postgres 对我来说效果很好。你有没有像这样在 config.js 中正确设置方言、协议(protocol)、端口

{
"development":{
"username":"name",
"password":"pass",
"database":"db",
"dialect":"postgres",
"protocol":"postgres",
"host":"127.0.0.1",
"port":"5432"
},
...

关于node.js - 使用 sequelize postgres 时出现语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22764596/

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