仅适用于 Postgres:对于外键限制,您可以使用 Truncate Cascade,这也会截断所有相关表。 cursor.execute('TRUNCATE TABLE "{0}" CASCADE'.format(MyModel._meta.db_table)) 10投票 除了Ned Batchelder 的回答并参考 Bernhard Kircher 的评论: 就我而言,我需要使用网络应用程序清空一个非常大的数据库: Book.obj...
Postgres 8.3 / Ubuntu Karmic / 32位(在VirtualBox中): duration: 76.534 ms statement: truncate audit.users cascade duration: 0.952 ms statement: delete from audit.users Postgres 8.4 / Ubuntu Lucid / 64位(本机,托管Karmic VirtualBox的机器上): duration: 1469.271 ms statement: truncate audit....
DETAIL: Table"users"references"tenants". HINT: Truncate table"users"at the same time, or use TRUNCATE ... CASCADE. Caused by: PG::FeatureNotSupported: ERROR: cannot truncate a table referencedina foreign key constraint (PG::FeatureNotSupported) DETAIL: Table"users"references"platform_tenants". ...