简体   繁体   中英

Migration file failed Knexjs

I'm not sure what is the problem with migration. I'm using knex to connect sqlite3 DB. I'm totally new to this.

Created table in migration file and then added a column in table using separate migration. But that file failed.

在此处输入图像描述

Logs shown above and I didn't diagnose why it's getting failed.

Migration for table creation is

import { Knex } from 'knex';
import { Bag } from '../../src/models';

    export const up = (knex: Knex): Promise<void> =>
      knex.schema.createTable(Bag.tableName, (table: Knex.TableBuilder) => {
        table.increments();
        table.timestamps();
        table.integer('volume');
      });
    
    export const down = (knex: Knex): Promise<void> =>
      knex.schema.dropTable(Bag.tableName);

Migration for adding column is

import { Knex } from 'knex';
import { Bag } from '../../src/models';

    export const up = (knex: Knex): Promise<void> =>
      knex.schema.alterTable(Bag.tableName, (table: Knex.TableBuilder) => {
        table.string('title');
      });
    
    export const down = (knex: Knex): Promise<void> =>
      knex.schema.alterTable(Bag.tableName, (table: Knex.TableBuilder) => {
        table.dropColumn('title');
      });

NOTE: I tried adding column in table creation migration but it also fails and gave me error.

在此处输入图像描述

Also when command to show completed migrations. It listed all migrations including new addedColumn one.

在此处输入图像描述

I didn't find an answer for this, why it's getting failed. After trying different methods, my problem was solved by making a new migration before running any migration.

This solved my problem. Although, it's not a solution but it solved my problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM