diff options
| author | Adnan Umer <u.adnan@outlook.com> | 2019-08-03 16:22:27 +0500 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-08-08 21:40:06 +0200 |
| commit | 1265a26b2fa3cbd73a2bccd91b700268bc28bc07 (patch) | |
| tree | 1c7a7a7bd04bc33fcc9e9e85a774807433d5ccf2 /django | |
| parent | 2c66f340bb50ed6790d839157dff64456b497a43 (diff) | |
[2.2.x] Fixed #30673 -- Relaxed system check for db_table collision when database routers are installed by turning the error into a warning.
Backport of 8d3519071ec001f763b70a3a1f98ae2e980bd552 from master.
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/checks/model_checks.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/django/core/checks/model_checks.py b/django/core/checks/model_checks.py index 8514fb4d12..eeb95dd6bc 100644 --- a/django/core/checks/model_checks.py +++ b/django/core/checks/model_checks.py @@ -4,7 +4,8 @@ from collections import defaultdict from itertools import chain from django.apps import apps -from django.core.checks import Error, Tags, register +from django.conf import settings +from django.core.checks import Error, Tags, Warning, register @register(Tags.models) @@ -29,14 +30,25 @@ def check_all_models(app_configs=None, **kwargs): ) else: errors.extend(model.check(**kwargs)) + if settings.DATABASE_ROUTERS: + error_class, error_id = Warning, 'models.W035' + error_hint = ( + 'You have configured settings.DATABASE_ROUTERS. Verify that %s ' + 'are correctly routed to separate databases.' + ) + else: + error_class, error_id = Error, 'models.E028' + error_hint = None for db_table, model_labels in db_table_models.items(): if len(model_labels) != 1: + model_labels_str = ', '.join(model_labels) errors.append( - Error( + error_class( "db_table '%s' is used by multiple models: %s." - % (db_table, ', '.join(db_table_models[db_table])), + % (db_table, model_labels_str), obj=db_table, - id='models.E028', + hint=(error_hint % model_labels_str) if error_hint else None, + id=error_id, ) ) return errors |
