The python manage.py flush
command can be used to erase all the data from the database tables.
You can know more about this command by typing,
python manage.py help flush
Or by typing,
python manage.py flush --help
It would give an output like this,
usage: manage.py flush [-h] [--noinput] [--database DATABASE] [--version] [-v {0,1,2,3}] [--settings SETTINGS]
[--pythonpath PYTHONPATH] [--traceback] [--no-color] [--force-color] [--skip-checks]
Removes ALL DATA from the database, including data added during migrations. Does not achieve a "fresh install" state.
optional arguments:
-h, --help show this help message and exit
--noinput, --no-input
Tells Django to NOT prompt the user for input of any kind.
--database DATABASE Nominates a database to flush. Defaults to the "default" database.
--version Show program's version number and exit.
-v {0,1,2,3}, --verbosity {0,1,2,3}
Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very verbose output
--settings SETTINGS The Python path to a settings module, e.g. "myproject.settings.main". If this isn't provided,
the DJANGO_SETTINGS_MODULE environment variable will be used.
--pythonpath PYTHONPATH
A directory to add to the Python path, e.g. "/home/djangoprojects/myproject".
--traceback Raise on CommandError exceptions.
--no-color Don't colorize the command output.
--force-color Force colorization of the command output.
--skip-checks Skip system checks.
When you give python manage.py flush
on the command prompt,
python manage.py flush
It will ask for a confirmation that once this command is executed it will erase all the data permanently. Django will proceed to erase all data from the database, including all records in the tables associated with your models on giving yes.
You need to be careful when using the flush
command, as it permanently deletes all data from the database tables. Make sure to back up your data if needed before running this command in a production environment.