django flush database

  1. Open a terminal window.

  2. Navigate to the root directory of your Django project using the "cd" command.

  3. Run the following command to activate the virtual environment:

source venv/bin/activate

(Note: Replace "venv" with the name of your virtual environment if it's different.)

  1. Execute the following command to flush the database:
python manage.py flush
  1. You will be prompted with a warning message about flushing the database. Type 'yes' and press Enter to confirm.

  2. Django will proceed to flush the database, which involves resetting the database to an empty state while maintaining the database schema.

  3. After the flush is complete, you may need to recreate the initial database schema and apply migrations. Run the following commands:

python manage.py makemigrations
python manage.py migrate
  1. Optionally, you may want to create a superuser for the Django admin interface by running:
python manage.py createsuperuser

Follow the prompts to set a username, email, and password for the superuser.

  1. The database is now flushed, and your Django project is ready with a clean database and the initial schema applied.

Note: Use these commands with caution, as the "flush" command will remove all data from the database, and this action cannot be undone. Ensure you have a backup or are working on a development database before running these commands in a production environment.