knex.js - 如何针对远程数据库运行 Knex 迁移?

标签 knex.js

我有一个远程数据库,我想对其运行 Knex 迁移。

我看到 Knex CLI 文档中有一个 --connection 标志,但是当我尝试

knex migrate:latest --connection [[my connection string]

我明白了

error: unknown option `--connection'

最佳答案

http://knexjs.org/#Migrations-CLI

你应该有knexfile.js在您的项目文件夹中。 文件应包含如下内容:

module.exports = {
  development: {
    client: 'mysql',
    connection: {
      host : '127.0.0.1', // should be remote host
      user : 'your_database_user',
      password : 'your_database_password',
      database : 'myapp_test'
    }
  }
}

然后您可以运行迁移

作者:npx knex migrate:latest

关于knex.js - 如何针对远程数据库运行 Knex 迁移?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60956215/

相关文章:

reactjs - 如何在Electron应用程序中处理数据库查询(使用react-redux)?

node.js - Knex 迁移不创建表

javascript - 在 Knex dateTime()/MySQL DATETIME 字段中存储 Node.js 日期

sql - Knex + Postgresql + node - 如何为选定的列调用 postgresql 函数

postgresql - 错误 : connect ECONNREFUSED 127. 0.1.1:5432

node.js - 传递到 Handlebars 的数据未显示

database - Knex Id 列被连接表 id 覆盖

javascript - 使用 knex js 时如何返回值?

mysql - 如何调试 knex.js?不必污染我的数据库

apollo-server - 如何在 Apollo GraphQL Server 上同步使用 Knexjs