Feanor
Feanor

Reputation: 3690

Django postgresql drop all tables and syncdb

I have database in PostgreSql named "tests". And i want to write sh script to syncdb it with django, run tests and then drop all tables. Can anyone suggest a proper solution? A bit of script:

DJANGO_DATABASE='tests' bin/django-admin.py syncdb  
bin/django-admin.py test MyApplication #tests will use "tests" db
sudo su postgres
psql tests
drop schema public; #i think i can drop schema and then syncdb.. or i'm wrong.
exit

Upvotes: 0

Views: 2507

Answers (1)

mo.
mo.

Reputation: 3534

As far as i know, django can do this for you. <-- outdated

Actually, it changed a bit :). But it's still possible:

#!/usr/bin/env sh
./manage.py sqlclear | ./manage.py dbshell
./manage.py syncdb

this will pipe, the output of sqlclear management-command into the dbshell. which will in turn execute it.

sqlclear will output DROP TABLE ... sql-statements.

Upvotes: 3

Related Questions