【发布时间】:2021-03-17 00:17:42
【问题描述】:
我正在尝试在某个目录(数据库目录)中迁移和播种。但是当我运行时:
npx knex migrate:make testing_table
它显示:
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
at validateString (internal/validators.js:124:11)
目录
- 主文件夹
- 客户
- 服务器
- 数据库
- 迁移
- Knexfile.js
- 公开
- 数据库
- Package.json
- 等
我所做的是将 knexfile.js 移到数据库目录之外并进入主目录。它可以工作并进行迁移,但它会在主文件夹中创建另一个迁移文件夹,而不是在当前迁移文件夹中创建表。
代码如下:
连接:
const config = require('../db/knexfile')
const env = process.env.NODE_ENV || 'development'
const connection = knex(config[env])
module.exports = connection
knex 文件:
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')
}
}
}
【问题讨论】:
-
问题是什么? ;-)
-
为没有澄清而道歉。如何从特定目录迁移表?
-
我编辑了这篇文章,希望它更有意义。
-
看看
npx knex --help,看看您是否可以从源代码之外指定配置。
标签: database path migration knex.js