简体   繁体   English

无法使用Azure上的Knex迁移生产数据库

[英]Unable to migrate production database with Knex on Azure

I am new to Knex.js and I had some issue running migration. 我是Knex.js的新手,我在运行迁移时遇到了一些问题。 I have an App that is running on Azure. 我有一个在Azure上运行的应用程序。 Now, I need to migrate my production database. 现在,我需要迁移我的生产数据库。

I am following the knex instruction and add the flag for environment by running the following. 我正在遵循knex指令,并通过运行以下命令为环境添加标志。

knex migrate:latest --env production

However, I am unable to migrate the database, it seems like I am still trying to access the local database. 但是,我无法迁移数据库,似乎我仍在尝试访问本地数据库。 Part of my error code are as follow: 部分错误代码如下:

Error: connect EACCES 127.0.0.1:5432
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)

I have no clue how this happen. 我不知道这是怎么发生的。 I am running the command on Azure App Service Editor. 我在Azure App Service Editor上运行该命令。 I also attach my knexfile.js 我还附上了我的knexfile.js

    production: {
    client: 'postgresql',
    connection: `host=${process.env.DB_HOST} port=5432 dbname=${process.env.DB_NAME} user=${process.env.DB_USER} password=${process.env.DB_PASS} sslmode=required`,
    pool: {
        min: 2,
        max: 10,
    },
    migrations: {
        directory: './db/migrations',
        tableName: 'migrations'
    },
    seeds: {
        directory: './db/seeds'
    }
},

You are passing connection parameters as template string and it is not recognizable by the pg module that is used under the hood and I guess it replaces it with the default value. 您将连接参数作为模板字符串传递,并且在引擎盖下使用的pg模块无法识别它,我猜它将使用默认值替换它。

Try to replace connection with the object 尝试用对象替换连接

connection: {
  host: process.env.DB_HOST,
  port: 5432,
  database: process.env.DB_NAME,
  user: process.env.DB_USER,
  password: process.env.DB_PASS
}

Not sure about the sslmode as I don't know whether this option exists in knex . 不知道的sslmode ,因为我不知道是否存在这个选项knex

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM