Reputation: 41
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 ..?
Upvotes: 4
Views: 9355
Reputation: 1
It must be alter table and the column is a readonly string, like this:
await knex.schema.alterTable('page_block_data', (table) => {
table.dropForeign(['page_block_data_block_id_foreign']);
});
Upvotes: 0
Reputation: 71
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');
});
};
Upvotes: 7
Reputation: 1
It need a readonly string[]. Maybe you can try:
table.dropForeign(['page_block_data_block_id_foreign']);
Upvotes: 0