189👍
reset
has been replaced by flush
with Django 1.5, see:
python manage.py help flush
42👍
It looks like the ‘flush’ answer will work for some, but not all cases. I needed not just to flush the values in the database, but to recreate the tables properly. I’m not using migrations yet (early days) so I really needed to drop all the tables.
Two ways I’ve found to drop all tables, both require something other than core django.
If you’re on Heroku, drop all the tables with pg:reset:
heroku pg:reset DATABASE_URL
heroku run python manage.py syncdb
If you can install Django Extensions, it has a way to do a complete reset:
python ./manage.py reset_db --router=default
- [Django]-Create empty queryset by default in django form fields
- [Django]-CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False
- [Django]-How do I use pagination with Django class based generic ListViews?
27👍
Similar to LisaD’s answer, Django Extensions has a great reset_db command that totally drops everything, instead of just truncating the tables like “flush” does.
python ./manage.py reset_db
Merely flushing the tables wasn’t fixing a persistent error that occurred when I was deleting objects. Doing a reset_db fixed the problem.
- [Django]-Django :How to integrate Django Rest framework in an existing application?
- [Django]-Saving ModelForm error(User_Message could not be created because the data didn't validate)
- [Django]-How to submit form without refreshing page using Django, Ajax, jQuery?
- [Django]-Data Mining in a Django/Postgres application
- [Django]-Add rich text format functionality to django TextField
- [Django]-Include intermediary (through model) in responses in Django Rest Framework
22👍
If you want to clean the whole database, you can use:
python manage.py flush
If you want to clean the database table of a Django app, you can use:
python manage.py migrate <app-name> zero
- [Django]-H14 error in heroku – "no web processes running"
- [Django]-How to pass information using an HTTP redirect (in Django)
- [Django]-Django values_list vs values
13👍
With django 1.11, simply delete all migration files from the migrations
folder of each application (all files except __init__.py
). Then
- Manually drop database.
- Manually create database.
- Run
python3 manage.py makemigrations
. - Run
python3 manage.py migrate
.
And voilla, your database has been completely reset.
- [Django]-When saving, how can you check if a field has changed?
- [Django]-How do I add a placeholder on a CharField in Django?
- [Django]-Django dynamic forms – on-the-fly field population?
6👍
python manage.py flush
deleted old db contents,
Don’t forget to create new superuser:
python manage.py createsuperuser
- [Django]-What's the purpose of Django setting ‘SECRET_KEY’?
- [Django]-How can I avoid "Using selector: EpollSelector" log message in Django?
- [Django]-Paginating the results of a Django forms POST request
4👍
For me this solved the problem.
heroku pg:reset DATABASE_URL
heroku run bash
>> Inside heroku bash
cd app_name && rm -rf migrations && cd ..
./manage.py makemigrations app_name
./manage.py migrate
- [Django]-Complete django DB reset
- [Django]-Django's Double Underscore
- [Django]-Django: Example of generic relations using the contenttypes framework?
3👍
Just a follow up to @LisaD’s answer.
As of 2016 (Django 1.9
), you need to type:
heroku pg:reset DATABASE_URL
heroku run python manage.py makemigrations
heroku run python manage.py migrate
This will give you a fresh new database within Heroku.
- [Django]-How to use MySQLdb with Python and Django in OSX 10.6?
- [Django]-No URL to redirect to. Either provide a url or define a get_absolute_url method on the Model
- [Django]-How can I disable logging while running unit tests in Python Django?
3👍
-
Just manually delete you database. Ensure you create backup first (in my case db.sqlite3 is my database)
-
Run this command
manage.py migrate
- [Django]-How to add multiple objects to ManyToMany relationship at once in Django ?
- [Django]-Can we append to a {% block %} rather than overwrite?
- [Django]-Suppress "?next=blah" behavior in django's login_required decorator
- [Django]-Django 2.0 – Not a valid view function or pattern name (Customizing Auth views)
- [Django]-Does django with mongodb make migrations a thing of the past?
- [Django]-Good open source django project for learning