diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2017-09-17 08:26:18 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-09-18 14:22:33 -0400 |
| commit | cee07ba0880e9d1396795e4823a7371da90cc5cc (patch) | |
| tree | 815468e42d3070a762a884e5605cc74691f22c70 /django | |
| parent | a86d95726bdf84efaba7f30c44edddf6c34d2c2e (diff) | |
[1.11.x] Fixed #28597 -- Fixed crash with the name of a model's autogenerated primary key in an Index's fields.
Backport of fb02ebe889eee292144f9157ed4ddcdcc139eba9 from master
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/base.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/django/db/models/base.py b/django/db/models/base.py index 5067fb9e4f..cf8f44919c 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -306,12 +306,6 @@ class ModelBase(type): # Copy indexes so that index names are unique when models extend an # abstract model. new_class._meta.indexes = [copy.deepcopy(idx) for idx in new_class._meta.indexes] - # Set the name of _meta.indexes. This can't be done in - # Options.contribute_to_class() because fields haven't been added to - # the model at that point. - for index in new_class._meta.indexes: - if not index.name: - index.set_name_with_model(new_class) if abstract: # Abstract base models can't be instantiated and don't appear in @@ -371,6 +365,13 @@ class ModelBase(type): manager.auto_created = True cls.add_to_class('objects', manager) + # Set the name of _meta.indexes. This can't be done in + # Options.contribute_to_class() because fields haven't been added to + # the model at that point. + for index in cls._meta.indexes: + if not index.name: + index.set_name_with_model(cls) + class_prepared.send(sender=cls) def _requires_legacy_default_manager(cls): # RemovedInDjango20Warning |
