django reset database
To reset the database in Django, you can follow these steps:
Open the terminal or command prompt and navigate to the directory where your Django project is located.
Run the following command to create a new migration file for resetting the database:
python manage.py makemigrations
Apply the migration to the database by running the following command:
python manage.py migrate --fake
Delete the existing database file, which is typically named
db.sqlite3
ordb.sqlite3.db
. You can use the following command to delete the file:rm db.sqlite3
Create a new, empty database by running the following command:
python manage.py migrate
(Optional) If you have any initial data that you want to load into the database, you can use fixtures. Create a fixture file with the necessary data (e.g., in JSON or YAML format) and load it into the database using the following command:
python manage.py loaddata <fixture_file>
Finally, start the development server and test your Django application with the reset database:
python manage.py runserver
These steps will reset the database in Django by creating a new migration file, applying the fake migration, deleting the existing database file, creating a new empty database, and optionally loading initial data using fixtures.