在我的Node.js应用程序中使用Knex.js删除迁移 [英] Removing Migrations With Knex.js In My Node.js Application

查看:81
本文介绍了在我的Node.js应用程序中使用Knex.js删除迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让knex在我的node.js应用程序中工作.我正在学习一个教程,并在某个时候创建​​了一个表格,但是无法重复该过程.我删除了表并删除了所有迁移文件夹.到目前为止,我重新开始,但是在创建新迁移并运行knex migrate:latest之后,我收到一条错误消息,指出迁移目录已损坏,因为我缺少原始迁移.

I am trying to get knex working in my node.js application. I was following a tutorial and at some point created a table but could not repeat the process. I removed the table and deleted all the migrations folders. At tis point I started over but after creating a new migration and then running knex migrate:latest I get an error saying the migration directory is corrupt because the original migration I had is missing.

我给人的印象是,如果文件丢失,则不应该知道它在那里.

I was under the impression that if the file is missing it should not know it was ever there.

从我的项目中删除迁移的正确方法是什么?

What is the proper way to remove a migration from my project?

knexfile.js

knexfile.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

但是此迁移不存在,因为我已将其删除.

but this migration does not exist because I deleted it.

推荐答案

您必须在删除文件之前回滚迁移(knex migrate:rollback),我想您可以做的是:

You had to rollback a migration (knex migrate:rollback) before deleting the file, I guess what you can do is:

touch [full_path_to_migrations_here]/migrations/20161110130954_auth_level.js

knex migrate:rollback

rm [full_path_to_migrations_here]/migrations/20161110130954_auth_level.js

此处参考 https://github.com/tgriesser/knex/issues/1569

这篇关于在我的Node.js应用程序中使用Knex.js删除迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆