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)
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.
knex.schema.dropTable(tableName) Drops a table, specified by tableName.
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);
I just do it with raw sql:
return knex.raw('DROP TABLE application CASCADE');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With