|
@@ -10,6 +10,10 @@ from django.test import SimpleTestCase, TestCase
|
|
|
from django.test.utils import isolate_apps, override_settings, register_lookup
|
|
|
|
|
|
|
|
|
+class EmptyRouter:
|
|
|
+ pass
|
|
|
+
|
|
|
+
|
|
|
def get_max_column_name_length():
|
|
|
allowed_len = None
|
|
|
db_alias = None
|
|
@@ -1044,6 +1048,32 @@ class OtherModelTests(SimpleTestCase):
|
|
|
)
|
|
|
])
|
|
|
|
|
|
+ @override_settings(DATABASE_ROUTERS=['invalid_models_tests.test_models.EmptyRouter'])
|
|
|
+ def test_m2m_table_name_clash_database_routers_installed(self):
|
|
|
+ class Foo(models.Model):
|
|
|
+ bar = models.ManyToManyField('Bar', db_table='myapp_bar')
|
|
|
+
|
|
|
+ class Meta:
|
|
|
+ db_table = 'myapp_foo'
|
|
|
+
|
|
|
+ class Bar(models.Model):
|
|
|
+ class Meta:
|
|
|
+ db_table = 'myapp_bar'
|
|
|
+
|
|
|
+ self.assertEqual(Foo.check(), [
|
|
|
+ Warning(
|
|
|
+ "The field's intermediary table 'myapp_bar' clashes with the "
|
|
|
+ "table name of 'invalid_models_tests.Bar'.",
|
|
|
+ obj=Foo._meta.get_field('bar'),
|
|
|
+ hint=(
|
|
|
+ "You have configured settings.DATABASE_ROUTERS. Verify "
|
|
|
+ "that the table of 'invalid_models_tests.Bar' is "
|
|
|
+ "correctly routed to a separate database."
|
|
|
+ ),
|
|
|
+ id='fields.W344',
|
|
|
+ ),
|
|
|
+ ])
|
|
|
+
|
|
|
def test_m2m_field_table_name_clash(self):
|
|
|
class Foo(models.Model):
|
|
|
pass
|
|
@@ -1069,6 +1099,32 @@ class OtherModelTests(SimpleTestCase):
|
|
|
)
|
|
|
])
|
|
|
|
|
|
+ @override_settings(DATABASE_ROUTERS=['invalid_models_tests.test_models.EmptyRouter'])
|
|
|
+ def test_m2m_field_table_name_clash_database_routers_installed(self):
|
|
|
+ class Foo(models.Model):
|
|
|
+ pass
|
|
|
+
|
|
|
+ class Bar(models.Model):
|
|
|
+ foos = models.ManyToManyField(Foo, db_table='clash')
|
|
|
+
|
|
|
+ class Baz(models.Model):
|
|
|
+ foos = models.ManyToManyField(Foo, db_table='clash')
|
|
|
+
|
|
|
+ self.assertEqual(Bar.check() + Baz.check(), [
|
|
|
+ Warning(
|
|
|
+ "The field's intermediary table 'clash' clashes with the "
|
|
|
+ "table name of 'invalid_models_tests.%s.foos'."
|
|
|
+ % clashing_model,
|
|
|
+ obj=model_cls._meta.get_field('foos'),
|
|
|
+ hint=(
|
|
|
+ "You have configured settings.DATABASE_ROUTERS. Verify "
|
|
|
+ "that the table of 'invalid_models_tests.%s.foos' is "
|
|
|
+ "correctly routed to a separate database." % clashing_model
|
|
|
+ ),
|
|
|
+ id='fields.W344',
|
|
|
+ ) for model_cls, clashing_model in [(Bar, 'Baz'), (Baz, 'Bar')]
|
|
|
+ ])
|
|
|
+
|
|
|
def test_m2m_autogenerated_table_name_clash(self):
|
|
|
class Foo(models.Model):
|
|
|
class Meta:
|
|
@@ -1090,6 +1146,33 @@ class OtherModelTests(SimpleTestCase):
|
|
|
)
|
|
|
])
|
|
|
|
|
|
+ @override_settings(DATABASE_ROUTERS=['invalid_models_tests.test_models.EmptyRouter'])
|
|
|
+ def test_m2m_autogenerated_table_name_clash_database_routers_installed(self):
|
|
|
+ class Foo(models.Model):
|
|
|
+ class Meta:
|
|
|
+ db_table = 'bar_foos'
|
|
|
+
|
|
|
+ class Bar(models.Model):
|
|
|
+ # The autogenerated db_table is bar_foos.
|
|
|
+ foos = models.ManyToManyField(Foo)
|
|
|
+
|
|
|
+ class Meta:
|
|
|
+ db_table = 'bar'
|
|
|
+
|
|
|
+ self.assertEqual(Bar.check(), [
|
|
|
+ Warning(
|
|
|
+ "The field's intermediary table 'bar_foos' clashes with the "
|
|
|
+ "table name of 'invalid_models_tests.Foo'.",
|
|
|
+ obj=Bar._meta.get_field('foos'),
|
|
|
+ hint=(
|
|
|
+ "You have configured settings.DATABASE_ROUTERS. Verify "
|
|
|
+ "that the table of 'invalid_models_tests.Foo' is "
|
|
|
+ "correctly routed to a separate database."
|
|
|
+ ),
|
|
|
+ id='fields.W344',
|
|
|
+ ),
|
|
|
+ ])
|
|
|
+
|
|
|
def test_m2m_unmanaged_shadow_models_not_checked(self):
|
|
|
class A1(models.Model):
|
|
|
pass
|