test django migrations without applying them
Open a terminal and navigate to your Django project directory.
Run the following command to generate an initial migration for your app:
python manage.py makemigrations your_app_name
- Run the following command to display the SQL statements for the migration without applying them:
python manage.py sqlmigrate your_app_name migration_name
Replace "your_app_name" with the actual name of your Django app and "migration_name" with the name of the migration you want to test.
- If you want to check the SQL for the latest migration, you can omit the migration name:
python manage.py sqlmigrate your_app_name
- Review the SQL statements displayed in the terminal to ensure they are correct.
Note: This process helps you preview the SQL statements that will be executed when applying a migration without actually applying them to the database.