diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2014-07-28 10:47:28 -0700 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2014-07-28 10:47:28 -0700 |
| commit | d6e73a876d77e889efe839345d39690a7004e2f4 (patch) | |
| tree | b9b31188450208d950f9ddfbd49c0cec2c2e89db /django | |
| parent | cb60d22bd94738174440f8d60a04c3d9c38636c9 (diff) | |
Fixed #23121: AlterModelOptions operation not changing state right
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/migrations/autodetector.py | 16 | ||||
| -rw-r--r-- | django/db/migrations/operations/models.py | 14 |
2 files changed, 17 insertions, 13 deletions
diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py index dfbfe869fd..e27d8ace74 100644 --- a/django/db/migrations/autodetector.py +++ b/django/db/migrations/autodetector.py @@ -10,6 +10,7 @@ from django.db.migrations import operations from django.db.migrations.migration import Migration from django.db.migrations.questioner import MigrationQuestioner from django.db.migrations.optimizer import MigrationOptimizer +from django.db.migrations.operations.models import AlterModelOptions class MigrationAutodetector(object): @@ -25,17 +26,6 @@ class MigrationAutodetector(object): if it wishes, with the caveat that it may not always be possible. """ - # Model options we want to compare and preserve in an AlterModelOptions op - ALTER_OPTION_KEYS = [ - "get_latest_by", - "ordering", - "permissions", - "default_permissions", - "select_on_save", - "verbose_name", - "verbose_name_plural", - ] - def __init__(self, from_state, to_state, questioner=None): self.from_state = from_state self.to_state = to_state @@ -864,11 +854,11 @@ class MigrationAutodetector(object): new_model_state = self.to_state.models[app_label, model_name] old_options = dict( option for option in old_model_state.options.items() - if option[0] in self.ALTER_OPTION_KEYS + if option[0] in AlterModelOptions.ALTER_OPTION_KEYS ) new_options = dict( option for option in new_model_state.options.items() - if option[0] in self.ALTER_OPTION_KEYS + if option[0] in AlterModelOptions.ALTER_OPTION_KEYS ) if old_options != new_options: self.add_operation( diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py index 1ded7c6db4..4e8100a5bb 100644 --- a/django/db/migrations/operations/models.py +++ b/django/db/migrations/operations/models.py @@ -337,6 +337,17 @@ class AlterModelOptions(Operation): may still need them. """ + # Model options we want to compare and preserve in an AlterModelOptions op + ALTER_OPTION_KEYS = [ + "get_latest_by", + "ordering", + "permissions", + "default_permissions", + "select_on_save", + "verbose_name", + "verbose_name_plural", + ] + def __init__(self, name, options): self.name = name self.options = options @@ -345,6 +356,9 @@ class AlterModelOptions(Operation): model_state = state.models[app_label, self.name.lower()] model_state.options = dict(model_state.options) model_state.options.update(self.options) + for key in self.ALTER_OPTION_KEYS: + if key not in self.options and key in model_state.options: + del model_state.options[key] def database_forwards(self, app_label, schema_editor, from_state, to_state): pass |
