SailsJS - Error occurred connecting to multiple database: error: syntax error at or near "SELEC"

SailsJS - Error occurred connecting to multiple database: error: syntax error at or near "SELEC"

我的应用程序中使用了 MongoDB,现在我需要连接到 Postgresql 以获取一些其他数据。但是在我为 Postgresql 添加连接和模型之后,当我使用 sails lift 启动应用程序时发生错误。以下是整个错误消息:

error: A hook (`orm`) failed to load!
error: Error (E_UNKNOWN) :: Encountered an unexpected error
error: syntax error at or near "SELEC"
  at Connection.parseE (/Users/xx/Documents/xx/Code/services/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:539:11)
  at Connection.parseMessage (/Users/xx/Documents/xx/Code/services/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:366:17)
  at Socket.<anonymous> (/Users/xx/Documents/xx/Code/services/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:105:22)
  at emitOne (events.js:96:13)
  at Socket.emit (events.js:188:7)
  at readableAddChunk (_stream_readable.js:172:18)
  at Socket.Readable.push (_stream_readable.js:130:10)
  at TCP.onread (net.js:535:20)

我比较工作应用程序所做的所有更改是:

  1. models.js 中添加了 connection: 'mongodb' 以将 MongoDB 设置为默认数据库连接。
  2. 在我新创建的模型 (ActivityController) 中添加 connection: 'postgresdb' 以连接到 Postgresql。

这花了我很多时间。由于我对文档的调查和学习,似乎所有配置都可以。我错过了什么吗?

如果有人能提供帮助,我将不胜感激。

终于找到病根了,差点崩溃。因为默认连接是 MongoDB,而 migrate 的值设置为 alter,所以使用 PostgreSQL 的模型使用这种自动迁移策略。这就是它试图操纵数据库的原因,这实际上可以从错误消息中推断出来。

因此,在我将 migrate: safe 添加到连接到 PostgreSQL 的模型后,它就起作用了。

以下是 SailsJS 文档中的自动迁移策略。

Auto-migration strategy | Description

safe                 | never auto-migrate my database(s). I will do it myself, by hand.

alter                | auto-migrate columns/fields, but attempt to keep my existing data (experimental)

drop                 | wipe/drop ALL my data and rebuild models every time I lift Sails