SailsJS / Waterline无法在Postgres中创建模型

时间:2015-10-17 20:03:53

标签: node.js postgresql sails.js waterline sails-postgresql

我试图将我的Sails JS应用程序部署到标准的Ubuntu 14.04.3 VM上。

现在,我无法将我的SailsJS实例与PostgreSQL服务器实例连接起来。 SailsJS服务器和PostgreSQL服务器都在同一个VM中运行。

我从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表,我不知道为什么。 非常感谢任何帮助!

1 个答案:

答案 0 :(得分:3)

如果您使用sails lift --prod在生产模式下抬起,风帆会迫使水线进入“安全”状态。模式。在安全模式下,不会进行任何数据库更改,包括表的初始设置。

要预先构建模型,您需要在没有prod标志的情况下运行sails lift。理想情况下,如果您使用部署脚本,这是构建过程的一部分。