我正在尝试让 knex 在我的 node.js 应用程序中工作。我正在学习教程并在某个时候创建了一个表但无法重复该过程。我删除了表格并删除了所有迁移文件夹。此时我重新开始,但在创建新迁移然后运行 knex migrate:latest
后,我收到一条错误消息,指出迁移目录已损坏,因为我的原始迁移丢失了。
我的印象是,如果文件丢失,它应该不知道它曾经存在过。
从我的项目中删除迁移的正确方法是什么?
knex文件.js
development: {
client: 'pg',
connection: {
host: '127.0.0.1',
user: 'postgres',
password: 'password',
database: 'myDatabase'
},
pool: {
min: 10,
max: 20
},
migrations: {
directory: __dirname + '/db/migrations'
},
seeds: {
directory: __dirname + '/db/seeds/development'
}
db.js
var config = require('../knexfile.js');
var env = 'development';
var knex = require('knex')(config[env]);
module.exports = knex;
console.log('Getting knex');
knex.migrate.latest([config]);
console.log('Applying migration...');
运行这个会报错,
knex migrate:latest
Using environment: development
Error: The migration directory is corrupt, the following files are missing: 20161110130954_auth_level.js
但是这个迁移不存在,因为我删除了它。
最佳答案
您必须在删除文件之前回滚迁移 (knex migrate:rollback
),我想您可以做的是:
触摸 [full_path_to_migrations_here]/migrations/20161110130954_auth_level.js
knex 迁移:回滚
rm [full_path_to_migrations_here]/migrations/20161110130954_auth_level.js
关于javascript - 在我的 Node.js 应用程序中使用 Knex.js 删除迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40554540/