Heroku找不到ExpressJS / Knex迁移

时间:2019-09-16 14:30:22

标签: postgresql express heroku knex.js

我有一个Express.js api,它通过Knex / SQL查询使用Postgresql在本地工作。

我试图部署到Heroku,但是,当我尝试迁移数据库时,出现了Heroku找不到迁移文件的错误。

具体来说,当我运行迁移时,它会抛出:

  

使用环境:生产错误:ENOENT:没有此类文件或   目录,scandir'/ app / migrations'

我的迁移位于my_app / db / migrations。错误中提到的应用文件夹不存在。试图弄清楚如何指向正确的文件夹。

这是我的package.json:

if (input % 2 == 0) {
    input = input / 2;
} else {
    input = 3 * input + 1;
}

System.out.print(input + ", ");

我的knexfile(myapp / knexfile.js):

{
  "name": "writerboard-express-api",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "serve": "cross-env NODE_ENV=development nodemon server.js"
  },
  "keywords": [],
  "author": "dariusgoore <dariusgoore@gmail.com> (dariusgoore.com)",
  "license": "MIT",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.19.0",
    "cors": "^2.8.5",
    "dotenv": "^8.1.0",
    "express": "^4.17.1",
    "express-jwt": "^5.3.1",
    "jsonwebtoken": "^8.5.1",
    "knex": "^0.19.3",
    "objection": "^1.6.9",
    "objection-password": "^2.0.0",
    "passport": "^0.4.0",
    "passport-local": "^1.0.0",
    "pg": "^7.12.1"
  },
  "devDependencies": {
    "cross-env": "^5.2.1",
    "nodemon": "^1.19.1"
  }
}

这是来自heroku的服务器日志:

const dotenv = require('dotenv');
dotenv.config({ path: "../.env" });

module.exports = {

  development: {
    client: 'postgresql',
    connection: {
      database: 'writerboard_dev', // update with env var
      user:     'dariusgoore' // update with env var
    },
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      tableName: 'knex_migrations',
      directory: './db/migrations'
    },
    seeds: {
      directory: './db/seeds'
    }
  },

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

};

1 个答案:

答案 0 :(得分:0)

仅供参考,答案在knexfile.js中。需要为生产设置迁移目录。