Remove / Reset your migrations¶
Important
Unless you know what you’re doing, both of these commands should not be used once your project has gone live. In other words, they become essentially useless once real users start interacting with your application.
rm-migrations¶
Usage: rm-migrations [--skip-git-check] [APPS_DIR] [-h] [--completion COMPLETION]
Remove all migrations for the specified applications directory, intended only for development.
Options
[--skip-git-check] Do not check if your git repo is clean.
Arguments
[APPS_DIR] The path to your django apps directory.
Help
[-h, --help] Show this message and exit.
[--completion COMPLETION] Use `--completion generate` to print shell-specific completion source. Valid options: generate, complete.
It is a good idea to delete all migrations and recreate them from scratch when deploying your django project for the fist time.
This ensures a clean base without any remnants of testing or experimentation from the initial development phase. Even during development,
when exploring new ideas, it is often necessary to delete all migrations and start over. This command is designed for these scenarios,
as it deletes all migrations in your project.
The command checks the debug value of your project using the manage.py
file. If the debug value is set to False
, the command will fail.
It takes an optional argument, apps_dir
, which specifies the directory containing your apps. If no argument is provided, it assumes that the apps
directory has the same name as the current parent directory. For example, if your project is named my_awesome_project
, the command will assume that
the apps directory is a subdirectory with the same name, i.e., my_awesome_project/my_awesome_project
. This is the default project layout created
by the falco startproject command.
Example
falco rm-migrations
# or
falco rm-migrations my_apps_dir
Warning
This command will delete all your migrations files, be sure to commit your changes before running this command.
After deleting all your migrations, your next step might likely be to reset your database using a command like reset-db
from django-extensions. However, if you want to preserve your data,
then the following command might be a better option than running rm-migrations
altogether.
reset-migrations¶
Usage: reset-migrations [--skip-git-check] [APPS_DIR] [-h] [--completion COMPLETION]
Delete and recreate all migrations.
Options
[--skip-git-check] Do not check if your git repo is clean.
Arguments
[APPS_DIR] The path to your django apps directory.
Help
[-h, --help] Show this message and exit.
[--completion COMPLETION] Use `--completion generate` to print shell-specific completion source. Valid options: generate, complete.
This command works exactly like the rm-migration
command but goes a bit further. Here’s how it works:
First, it runs
falco rm-migrations
.Then, it clears your django migrations table:
from django.db import connection with connection.cursor() as cursor: cursor.execute("DELETE FROM django_migrations")
Next, it runs
python manage.py makemigrations
to recreate migrations.Lastly, it executes
python manage.py migrate --fake
add the new migrations to the migrations table so that your migrations are in sync with the current database schema state.
The migrate fake command apply migrations without running
the actual SQL.
Since the reset-migrations
depends on the rm-migrations
command, it performs the same checks: it checks your Django DEBUG
value and your Git
repo needs to be in a clean state unless you use the --skip-git-check
option.
This command allows you to restore your migrations to their initial state without losing any existing data.