【问题标题】:cannot migrate my knex migration table to postgres on heroku无法将我的 knex 迁移表迁移到 heroku 上的 postgres
【发布时间】:2021-06-17 19:14:57
【问题描述】:

我正在关注 youtube 上的教程,该教程在本地使用 node express knex 和 sqlite,在 heroku 上使用 postgres。我设法让一切都在本地使用 sqlite 工作,并设法在 heroku 上加载应用程序。我收到了最初的主页消息。我设法在 heroku 上创建了一个空白的 postgres 数据库,并且可以查看 heroku 上的数据库凭据。我需要将我的 knex 表迁移到 heroku postgres 数据库。根据下面的视频我需要使用这个指令

heroku run knex migrate:latest -a node-knex1

这给了我以下错误

Running knex migrate:latest on ⬢ node-knex1... up, run.3492 (Free)
Using environment: production
error: no pg_hba.conf entry for host "54.76.162.141", user "vnujkqszmxsboi", database "def52ulvb1tjg9", SSL off
    at Parser.parseErrorMessage (/app/node_modules/pg-protocol/dist/parser.js:278:15)
    at Parser.handlePacket (/app/node_modules/pg-protocol/dist/parser.js:126:29)
    at Parser.parse (/app/node_modules/pg-protocol/dist/parser.js:39:38)
    at Socket.<anonymous> (/app/node_modules/pg-protocol/dist/index.js:10:42)
    at Socket.emit (events.js:315:20)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9)
    at Socket.Readable.push (internal/streams/readable.js:223:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)

我的 knexfile.js 如下所示。

  module.exports = {
      development: {
        client: 'sqlite3',
        connection: {
          filename: './data/lessons.db3',
        },
        useNullAsDefault: true,
        pool: {
          afterCreate: (conn, done) => {
           conn.run('PRAGMA foreign_keys = ON', done);
          },
        },
      },
      production: {
        client: 'pg',
        connection: process.env.DATABASE_URL,
        pool: {
          min: 2,
          max: 10,
        },
        migrations: {
          tablename: 'knex-migrations',
          directory: './migrations',
        },
      },
    };

[Node Express Tutorial 18 - Setting up a Postgres database in 
Heroku][1]


  [1]: https://www.youtube.com/watch?v=OZQWfW3VvhE&list=PLKii3VqdFnoZY6EBxb2K37D0wrEmS-5RD&index=17

【问题讨论】:

    标签: node.js postgresql heroku


    【解决方案1】:

    我发现我可以通过将 knexfile.js 更改为接近 heroku 文档中的内容来解决我的问题。

    module.exports = {
      development: {
        client: 'sqlite3',
        connection: {
          filename: './data/lessons.db3',
        },
        useNullAsDefault: true,
        pool: {
          afterCreate: (conn, done) => {
            conn.run('PRAGMA foreign_keys = ON', done);
          },
        },
      },
      production: {
        client: 'pg',
        connection: {
          connectionString: process.env.DATABASE_URL,
          ssl: { rejectUnauthorized: false },
        },
        migrations: {
          directory: __dirname + '/migrations',
        },
        seeds: {
          directory: __dirname + '/seeds',
        },
      },
    };
    

    【讨论】:

      猜你喜欢
      • 2017-05-28
      • 2020-01-17
      • 2021-09-25
      • 2014-07-21
      • 2021-05-23
      • 2015-10-25
      • 2018-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多