2

This is such a noob question, but I have an issue with my test database.

I asked the question about a database error I have here.

I now think that if I drop the database and then re-create it, the issue that I have will be resolved.

I am running python 2.7, django 1.7 & postgressql 9.4.

How do I 'delete' the database and then recreate it?

I am unsure if I should drop the entire database from the pgAdmin console and then run migrations. I am unsure because if I do this and it it incorrect, I am not sure what to do next to recover.

I have done a data dump. I have all my migrations in place.

1 Answer 1

4

Well, Django by itself does not include what you want.

There are two commands you can use:

python manage.py help flush

This one will destroy all of the data in your database, but will not delete it.

To delete your database you need to run:

python manage.py sqlclear <app>

This command will print to the standard output the sql needed to drop the tables on an specific app, but it will not execute it.

If you really want to delete the database and create it again you can use django_extensions's reset_db command, which will destroy your database and create it again.

To install django_extensions (assuming you installed pip), just run:

pip install django_extensions

Then add django_extensions to your INSTALLED_APPS variable in settings.py.

After that feel free to run:

python manage.py reset_db

Hope it helps and create fixtures to provide initial data for your models...

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

1 Comment

averent, thank you. I used python manage.py reset_db to delete all the data and the tables - which helped a great deal.

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.