我正在尝试将我的 Sails JS 应用程序部署到标准的 Ubuntu 14.04.3 VM 上。
现在,我在将 SailsJS 实例与 PostgreSQL 服务器实例连接时遇到了问题。 SailsJS 服务器和 PostgreSQL 服务器都在同一个虚拟机中运行。
我从我的 Sails JS 日志中得到以下输出:
MySailsServer-0 Sending 500 ("Server Error") response:
Error (E_UNKNOWN) :: Encountered an unexpected error
error: relation "recording" does not exist
at Connection.parseE (/home/vmuser/MySailsServer/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:539:11)
at Connection.parseMessage (/home/vmuser/MySailsServer/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:366:17)
at Socket.<anonymous> (/home/vmuser/MySailsServer/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:105:22)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at Socket.Readable.push (_stream_readable.js:110:10)
at TCP.onread (net.js:523:20)
似乎我的Recording
模型没有在数据库中创建。
我检查了 Postgre 日志以获取更多信息。这是 cat/var/log/postgresql/postgresql-9.3-main.log
的输出:
2015-10-17 14:46:13 CDT ERROR: relation "recording" does not exist at character 491
2015-10-17 14:46:13 CDT STATEMENT: SELECT "recording"."startTime", "recording"."endTime", "recording"."filename", "recording"."id", "recording"."createdAt", "recording"."updatedAt", "recording"."section", "__section"."startTime" AS "section___startTime", "__section"."endTime" AS "section___endTime", "__section"."name" AS "section___name", "__section"."id" AS "section___id", "__section"."createdAt" AS "section___createdAt", "__section"."updatedAt" AS "section___updatedAt", "__section"."course" AS "section___course" FROM "recording" AS "recording" LEFT OUTER JOIN "section" AS "__section" ON "recording"."section" = "__section"."id" LIMIT 30 OFFSET 0
关于为什么我在 api/models/
下声明的模型都没有被制作成 PostgreSQL 中的表的任何线索?
这是我在 config/connections.js
下的配置:
postgresqlServer: {
adapter: 'sails-postgresql',
host: 'localhost',
user: <username>,
password: <password>,
database: <db_name>,
schema: true
}
在 config/models.js
下我放了:
module.exports.models = {
connection: 'postgresqlServer',
migrate: 'alter'
};
我看不出我做错了什么。似乎我的 SailsJS 模型没有被转换成 PostgreSQL 表,我不确定为什么。 非常感谢任何帮助!
最佳答案
如果您使用 sails lift --prod
在生产模式下提升,sails 会强制水线进入“安全”模式。在安全模式下,不会对数据库进行任何更改,包括表的初始设置。
要预先构建模型,您需要在没有 prod 标志的情况下运行 sails lift
。理想情况下,如果您使用部署脚本,这是构建过程的一部分。
关于node.js - SailsJS/Waterline 无法在 Postgres 中创建模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33191043/