我试图在某个目录(数据库dir)中迁移和播种。但当我跑的时候
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)目录
folder
- Public我所做的是将knexfile.js移出数据库目录并进入主目录。它工作并迁移,但它主要创建另一个迁移文件夹,而不是在当前迁移文件夹中创建一个表。
以下是代码:
连接:
const config = require('../db/knexfile')
const env = process.env.NODE_ENV || 'development'
const connection = knex(config[env])
module.exports = connectionknex档案:
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')
}
}
}发布于 2021-10-26 14:19:32
如果您已经将into文件移动到主文件夹中(正如您在文件夹结构中提到的那样),您必须按照以下方式更改迁移目录的路径:-
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
}}, https://stackoverflow.com/questions/66665333
复制相似问题