Opened 11 years ago
Last modified 11 years ago
#24543 closed New feature
Add checks / command options for "migrations not applied" and "migrations needed" — at Version 3
| Reported by: | Daniel Hahler | Owned by: | |
|---|---|---|---|
| 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 (last modified by )
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.
Change History (3)
comment:1 by , 11 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:2 by , 11 years ago
| Owner: | removed |
|---|---|
| Status: | assigned → new |
comment:3 by , 11 years ago
| Description: | modified (diff) |
|---|
As for me, I simply execute
migrateas part of a deployment script. If there aren't any migrations to apply, it's just a no-op. Could you elaborate on your use case for needing to know if migrations are applied or not? Currently,check --deployis simply a static analysis of a settings file. The check you proposed would require the ability to connect to the production database which might not be possible from a development machine.Regarding the second point,
makemigrationsgained an --exit option in 1.8 which does what you describe.