首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未能解析配置文件,k耐视无法确定在何处生成迁移。

未能解析配置文件,k耐视无法确定在何处生成迁移。
EN

Stack Overflow用户
提问于 2021-03-17 00:17:42
回答 1查看 3.8K关注 0票数 2

我试图在某个目录(数据库dir)中迁移和播种。但当我跑的时候

npx knex migrate:make testing_table

它显示:

代码语言:javascript
复制
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at validateString (internal/validators.js:124:11)

目录

folder

  • Client

  • Server
  • Main
    • 数据库

代码语言:javascript
复制
- Public

  • Package.json
  • etc.

我所做的是将knexfile.js移出数据库目录并进入主目录。它工作并迁移,但它主要创建另一个迁移文件夹,而不是在当前迁移文件夹中创建一个表。

以下是代码:

连接:

代码语言:javascript
复制
const config = require('../db/knexfile')
const env = process.env.NODE_ENV || 'development'
const connection = knex(config[env])

module.exports = connection

knex档案:

代码语言:javascript
复制
module.exports = {
  development: {
    client: 'sqlite3',
    connection: {
      filename: './dev.sqlite3'
    },
    useNullAsDefault: true,
    // Getting SQlite to honour contraints
    pool: {
      afterCreate: (conn, cb) =>
        conn.run('PRAGMA foreign_keys = ON', cb)
    }
  },

  test: {
    client: 'sqlite3',
    connection: {
      filename: ':memory:'
    },
    useNullAsDefault: true,
    seeds: {
      directory: path.join(__dirname, 'tests/seeds')
    },
    migrations: {
      directory: path.join(__dirname, 'migrations')
    }
  },

  production: {
    client: 'sqlite3',
    connection: process.env.DATABASE_URL,
    pool: {
      min: 2,
      max: 10
    },
    migrations: {
      directory: path.join(__dirname, './server/db/migrations')
    },
    seeds: {
      directory: path.join(__dirname, './seeds')
    }
  }
}
EN

回答 1

Stack Overflow用户

发布于 2021-10-26 14:19:32

如果您已经将into文件移动到主文件夹中(正如您在文件夹结构中提到的那样),您必须按照以下方式更改迁移目录的路径:-

代码语言:javascript
复制
test: {
client: 'sqlite3',
connection: {
  filename: ':memory:'
},
useNullAsDefault: true,
seeds: {
  directory: path.join(__dirname, 'tests/seeds')
},
migrations: {
  directory: path.join(__dirname, './Database/Migrations') //--Changed this line
}},   
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66665333

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档