我在尝试将我的 API 部署到 heroku 时遇到了这个问题

I am having this Issue when trying to deploy my API to heroku

我已经从 Heroku 安装了 PostgreSQL 附加组件,但我在后端使用 Knex.js,因为我之前使用 SQLite 时出现以下错误。

我正在为网站和移动应用程序构建后端并尝试将其部署到 Heroku,在开发过程中我使用的是 SQLite,但认为由于我使用的是 Knex.js,我可以轻松地转移到来自 Heroku 的 Postgres 附加组件。我 运行 陷入这个问题,当 运行 knex migrate:latestpostbuild.

no such file or directory, scandir '/tmp/build_46fb7aa66e7e3cea06d2f04a21ad9249/migrations'

这是我的 knex 文件:

// Update with your config settings.

module.exports = {

  development: {
    client: 'sqlite3',
    connection: {
      filename: './src/database/db.sqlite'
    },
    migrations: {
      directory: './src/database/migrations'
    },
    useNullAsDefault: true
  },


  test: {
    client: 'sqlite3',
    connection: {
      filename: './src/database/test.sqlite'
    },
    migrations: {
      directory: './src/database/migrations'
    },
    useNullAsDefault: true
  },

  staging: {
    client: 'postgresql',
    connection: {
      database: 'my_db',
      user:     'username',
      password: 'password'
    },
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      tableName: 'knex_migrations'
    }
  },

  production: {
    client: 'pg',
    debug: true,
    connection: process.env.DATABASE_URL,
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      tableName: 'knex_migrations'
    },
    ssl: true
  }

};

和我的人脉

const knex = require('knex')
const configuration = require('../../knexfile')

const config = process.env.NODE_ENV


const connection = knex(configuration[config])


module.exports = connection

用于测试和开发的迁移工作正常

我也不知道这之后是否会起作用,所以如果有人有任何经验,我可以提供任何帮助

Heroku 似乎找不到您的迁移。

您的生产配置似乎不包含迁移目录。尝试添加它,例如

  production: {
    client: 'pg',
    debug: true,
    connection: process.env.DATABASE_URL,
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      tableName: 'knex_migrations',
      directory: './src/database/migrations'  // <-- here
    },
    ssl: true
  }

when in development I was using SQLite, but figured that since I was using Knex.js, I could easily transfer to Postgres add-on from Heroku

我强烈建议您在开发和生产中使用相同的数据库。数据库引擎不是彼此的直接替代品,即使您使用的是 Knex 之类的东西。