0

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.

enter image description here

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.

enter image description here

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

enter image description here

Ahsan Danish
  • 91
  • 2
  • 12

1 Answers1

0

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.

Ahsan Danish
  • 91
  • 2
  • 12