[Django]-Delete all table without dropping database in postgres in django dbshell in one command?

66👍

If all of your tables are in a single schema, this approach could work (below code assumes that the name of your schema is ‘public’)

drop schema public cascade;
create schema public;

Drop all tables in PostgreSQL?

see above link for more answers

👤Haji

10👍

Run the following bash script:

psql -h <pg_host> -p <pg_port> -U <pg_user> <pg_db> -t -c "select 'drop table \"' || tablename || '\" cascade;' from pg_tables where schemaname='public'" | psql -h <pg_host> -p <pg_port> -U <pg_user> <pg_db>

I copied from here: http://www.commandlinefu.com/commands/view/12989/postgresql-drop-all-tables-from-a-schema

It worked for me.

Leave a comment