mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[1.9.x] Refs #25745 -- Avoided multiple registration of the same model in schema tests.
Backport of 64240263f2 from master
			
			
This commit is contained in:
		| @@ -64,6 +64,10 @@ class SchemaTests(TransactionTestCase): | |||||||
|             model._meta._expire_cache() |             model._meta._expire_cache() | ||||||
|         if 'schema' in new_apps.all_models: |         if 'schema' in new_apps.all_models: | ||||||
|             for model in self.local_models: |             for model in self.local_models: | ||||||
|  |                 for many_to_many in model._meta.many_to_many: | ||||||
|  |                     through = many_to_many.remote_field.through | ||||||
|  |                     if through and through._meta.auto_created: | ||||||
|  |                         del new_apps.all_models['schema'][through._meta.model_name] | ||||||
|                 del new_apps.all_models['schema'][model._meta.model_name] |                 del new_apps.all_models['schema'][model._meta.model_name] | ||||||
|  |  | ||||||
|     def delete_tables(self): |     def delete_tables(self): | ||||||
| @@ -1031,13 +1035,12 @@ class SchemaTests(TransactionTestCase): | |||||||
|         # Ensure there's no m2m table there |         # Ensure there's no m2m table there | ||||||
|         self.assertRaises(DatabaseError, self.column_classes, new_field.remote_field.through) |         self.assertRaises(DatabaseError, self.column_classes, new_field.remote_field.through) | ||||||
|  |  | ||||||
|         # Need to tear down using a model without the added M2M field that's |         # Make sure the model state is coherent with the table one now that | ||||||
|         # been removed. |         # we've removed the tags field. | ||||||
|         class LocalAuthorWithM2M(Model): |         opts = LocalAuthorWithM2M._meta | ||||||
|             class Meta: |         opts.local_many_to_many.remove(new_field) | ||||||
|                 app_label = 'schema' |         del new_apps.all_models['schema'][new_field.remote_field.through._meta.model_name] | ||||||
|                 apps = new_apps |         opts._expire_cache() | ||||||
|         self.local_models = [LocalAuthorWithM2M] |  | ||||||
|  |  | ||||||
|     def test_m2m(self): |     def test_m2m(self): | ||||||
|         self._test_m2m(ManyToManyField) |         self._test_m2m(ManyToManyField) | ||||||
| @@ -1139,13 +1142,8 @@ class SchemaTests(TransactionTestCase): | |||||||
|         ) |         ) | ||||||
|  |  | ||||||
|         # This model looks like the new model and is used for teardown. |         # This model looks like the new model and is used for teardown. | ||||||
|         class LocalBookWithM2M(Model): |         opts = LocalBookWithM2M._meta | ||||||
|             uniques = M2MFieldClass(UniqueTest) |         opts.local_many_to_many.remove(old_field) | ||||||
|  |  | ||||||
|             class Meta: |  | ||||||
|                 app_label = 'schema' |  | ||||||
|                 apps = new_apps |  | ||||||
|         self.local_models = [LocalBookWithM2M] |  | ||||||
|         # Ensure the new M2M exists and points to UniqueTest |         # Ensure the new M2M exists and points to UniqueTest | ||||||
|         constraints = self.get_constraints(new_field.remote_field.through._meta.db_table) |         constraints = self.get_constraints(new_field.remote_field.through._meta.db_table) | ||||||
|         if connection.features.supports_foreign_keys: |         if connection.features.supports_foreign_keys: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user