0

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

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Great! Can you explain how?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.