如何在PostgreSQL中使用Knex.js进行级联删除?

时间:2014-09-25 10:52:11

标签: postgresql bookshelf.js knex.js

尝试删除另一个表(页面)引用的表(应用程序)时出现此错误。

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

错误是

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)

1 个答案:

答案 0 :(得分:8)

我只是使用原始sql: return knex.raw('DROP TABLE application CASCADE');