Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I do a cascade drop using Knex.js in PostgreSQL?

I'm getting this error while trying to delete a table(application) which is referenced by another table (page) .

knex.schema.dropTable("application").exec();

Error is

Possibly unhandled error: cannot drop table application because other objects depend on it
at Connection.parseE (/home/balan/node_modules/pg/lib/connection.js:526:11)
at Connection.parseMessage (/home/balan/node_modules/pg/lib/connection.js:356:17)
at Socket.<anonymous> (/home/balan/node_modules/pg/lib/connection.js:105:22)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:745:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:407:10)
at emitReadable (_stream_readable.js:403:5)
at readableAddChunk (_stream_readable.js:165:9)
at Socket.Readable.push (_stream_readable.js:127:10)
like image 664
Balanarayanan Avatar asked Sep 25 '14 10:09

Balanarayanan


People also ask

What is drop cascade in PostgreSQL?

In PostgreSQL, the CASCADE option is used with the DROP TABLE statement to drop/delete a table and its dependent objects. To do so, specify the DROP TABLE command followed by the table name and then write the CASCADE to drop a table along with its dependent objects.

How do I drop a table in KNEX?

knex.schema.dropTable(tableName) Drops a table, specified by tableName.

How do I connect to PostgreSQL KNEX?

Connecting Knex with Postgres We specify the connection parameters for Postgres and point Knex to connect to the pg client. const db = require("knex")({ client: "pg", connection: { host: "localhost", user: "postgres", password: "", database: "knex-test" } }); app. set("db", db);


1 Answers

I just do it with raw sql: return knex.raw('DROP TABLE application CASCADE');

like image 153
Allie Hoch Janoch Avatar answered Oct 19 '22 06:10

Allie Hoch Janoch