diff options
| author | can <cansarigol@derinbilgi.com.tr> | 2019-05-01 16:39:02 +0300 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-05-02 09:13:20 +0200 |
| commit | bceadd2788dc2dad53eba0caae172bd8522fd483 (patch) | |
| tree | 7efb2d995f2a78b9b6a596303807d300a64febbf /django | |
| parent | 6485a5f450b3dc60e690c31a75e0e9574a896842 (diff) | |
Fixed #30396 -- Added system checks for uniqueness of indexes and constraints names.
Co-Authored-By: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/checks/model_checks.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/django/core/checks/model_checks.py b/django/core/checks/model_checks.py index 6c6ac2c7f4..5c2266ca1d 100644 --- a/django/core/checks/model_checks.py +++ b/django/core/checks/model_checks.py @@ -10,6 +10,8 @@ from django.core.checks import Error, Tags, register @register(Tags.models) def check_all_models(app_configs=None, **kwargs): db_table_models = defaultdict(list) + indexes = defaultdict(list) + constraints = defaultdict(list) errors = [] if app_configs is None: models = apps.get_models() @@ -29,6 +31,10 @@ def check_all_models(app_configs=None, **kwargs): ) else: errors.extend(model.check(**kwargs)) + for model_index in model._meta.indexes: + indexes[model_index.name].append(model._meta.label) + for model_constraint in model._meta.constraints: + constraints[model_constraint.name].append(model._meta.label) for db_table, model_labels in db_table_models.items(): if len(model_labels) != 1: errors.append( @@ -39,6 +45,32 @@ def check_all_models(app_configs=None, **kwargs): id='models.E028', ) ) + for index_name, model_labels in indexes.items(): + if len(model_labels) > 1: + model_labels = set(model_labels) + errors.append( + Error( + "index name '%s' is not unique %s %s." % ( + index_name, + 'for model' if len(model_labels) == 1 else 'amongst models:', + ', '.join(sorted(model_labels)), + ), + id='models.E029' if len(model_labels) == 1 else 'models.E030', + ), + ) + for constraint_name, model_labels in constraints.items(): + if len(model_labels) > 1: + model_labels = set(model_labels) + errors.append( + Error( + "constraint name '%s' is not unique %s %s." % ( + constraint_name, + 'for model' if len(model_labels) == 1 else 'amongst models:', + ', '.join(sorted(model_labels)), + ), + id='models.E031' if len(model_labels) == 1 else 'models.E032', + ), + ) return errors |
