mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
[multi-db] Added check in model validation for models related to other
models using a different connection. Removed special-case stringifying of _default connection. git-svn-id: http://code.djangoproject.com/svn/django/branches/multiple-db-support@3447 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
57208f6392
commit
f4a776eee7
@ -262,8 +262,6 @@ def _collate(connection_output, reverse=False):
|
|||||||
for connection_name, statements in connection_output.items():
|
for connection_name, statements in connection_output.items():
|
||||||
if not statements:
|
if not statements:
|
||||||
continue
|
continue
|
||||||
if connection_name is _default:
|
|
||||||
connection_name = '(default)'
|
|
||||||
final_output.append(' -- The following statements are for connection: %s' % connection_name)
|
final_output.append(' -- The following statements are for connection: %s' % connection_name)
|
||||||
if reverse:
|
if reverse:
|
||||||
statements.reverse()
|
statements.reverse()
|
||||||
@ -681,7 +679,7 @@ def get_validation_errors(outfile, app=None):
|
|||||||
validates all models of all installed apps. Writes errors, if any, to outfile.
|
validates all models of all installed apps. Writes errors, if any, to outfile.
|
||||||
Returns number of errors.
|
Returns number of errors.
|
||||||
"""
|
"""
|
||||||
from django.db import models
|
from django.db import models, model_connection_name
|
||||||
from django.db.models.loading import get_app_errors
|
from django.db.models.loading import get_app_errors
|
||||||
from django.db.models.fields.related import RelatedObject
|
from django.db.models.fields.related import RelatedObject
|
||||||
|
|
||||||
@ -692,7 +690,8 @@ def get_validation_errors(outfile, app=None):
|
|||||||
|
|
||||||
for cls in models.get_models(app):
|
for cls in models.get_models(app):
|
||||||
opts = cls._meta
|
opts = cls._meta
|
||||||
|
connection_name = model_connection_name(cls)
|
||||||
|
|
||||||
# Do field-specific validation.
|
# Do field-specific validation.
|
||||||
for f in opts.fields:
|
for f in opts.fields:
|
||||||
if f.name == 'id' and not f.primary_key and opts.pk.name == 'id':
|
if f.name == 'id' and not f.primary_key and opts.pk.name == 'id':
|
||||||
@ -730,6 +729,10 @@ def get_validation_errors(outfile, app=None):
|
|||||||
if f.rel.to not in models.get_models():
|
if f.rel.to not in models.get_models():
|
||||||
e.add(opts, "'%s' has relation with model %s, which has not been installed" % (f.name, rel_opts.object_name))
|
e.add(opts, "'%s' has relation with model %s, which has not been installed" % (f.name, rel_opts.object_name))
|
||||||
|
|
||||||
|
rel_connection = model_connection_name(f.rel.to)
|
||||||
|
if rel_connection != connection_name:
|
||||||
|
e.add(opts, "'%s' is configured to use connection '%s' but has relation with '%s', which is configured to use connection '%s'" % (cls.__name__, connection_name, f.rel.to.__name__, rel_connection))
|
||||||
|
|
||||||
rel_name = RelatedObject(f.rel.to, cls, f).get_accessor_name()
|
rel_name = RelatedObject(f.rel.to, cls, f).get_accessor_name()
|
||||||
rel_query_name = f.related_query_name()
|
rel_query_name = f.related_query_name()
|
||||||
for r in rel_opts.fields:
|
for r in rel_opts.fields:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user