Opened 10 years ago
Last modified 10 years ago
#24543 closed New feature
Add checks / command options for "migrations not applied" and "migrations needed" — at Initial Version
Reported by: | Daniel Hahler | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The runserver
command prints a notice in case migrations are not applied:
def check_migrations(self):
"""
Checks to see if the set of migrations on disk matches the
migrations in the database. Prints a warning if they don't match.
"""
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
plan = executor.migration_plan(executor.loader.graph.leaf_nodes())
if plan:
self.stdout.write(self.style.NOTICE("\nYou have unapplied migrations; your app may not work properly until they are applied."))
self.stdout.write(self.style.NOTICE("Run 'python manage.py migrate' to apply them.\n"))
I would like to use this test during deployment.
Maybe this would be appropriate for the new --deploy
option for the check
command introduced in Django 1.8?
Additionally, I'd like to check if there are no migrations required, which I
currently test by looking for "No changes detected"
in `makemigrations
--dry-run`.
Even when this doesn't fit into the checks system, there should be a supported
way to get theses information by means of return codes from a command.