Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop foreign key in knex.js migration is not working

I am using migration using knex.js on my sql . now there is some wrong foreign key and i want to remove it . I am using below syntax for that but it is not working . It is not showing any error but not removing foreign key also .

exports.up = function(knex, Promise) {
      knex.schema.table('page_block_data', function(table) {
        table.dropForeign('page_block_data_block_id_foreign');
      });

};

exports.down = () => {};

Can anyone help me for this issue ..?

like image 533
Kiran Kanani Avatar asked Sep 06 '25 17:09

Kiran Kanani


1 Answers

You are missing return from your up method. It may cause that DB connection is actually closed before query was sent to the DB server.

Also name table name prefix and postfix parts of the foreign key name is automatically generated.

try:

exports.up = function(knex, Promise) {
     return knex.schema.table('page_block_data', function(table) {
        table.dropForeign('block_id');
      });
};
like image 170
sara mohaghegh Avatar answered Sep 10 '25 05:09

sara mohaghegh