mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	[2.0.x] Fixed #28884 -- Fixed crash on SQLite when renaming a field in a model referenced by a ManyToManyField.
Introspected database constraints instead of relying on _meta.related_objects to determine whether or not a table or a column is referenced on rename operations. This has the side effect of ignoring both db_constraint=False and virtual fields such as GenericRelation which aren't backend by database level constraints and thus shouldn't prevent the rename operations from being performed in a transaction. Regression in095c1aaa89. Thanks Tim for the additional tests and edits, and Mariusz for the review. Backport of9f7772e098from master
This commit is contained in:
		
				
					committed by
					
						 Tim Graham
						Tim Graham
					
				
			
			
				
	
			
			
			
						parent
						
							17987b5511
						
					
				
				
					commit
					b40a1d774d
				
			| @@ -722,7 +722,7 @@ class OperationTests(OperationTestBase): | ||||
|  | ||||
|         project_state = self.apply_operations(app_label, project_state, operations=[ | ||||
|             migrations.RenameModel("Pony", "Pony2"), | ||||
|         ]) | ||||
|         ], atomic=connection.features.supports_atomic_references_rename) | ||||
|         Pony = project_state.apps.get_model(app_label, "Pony2") | ||||
|         Rider = project_state.apps.get_model(app_label, "Rider") | ||||
|         pony = Pony.objects.create() | ||||
| @@ -1231,12 +1231,13 @@ class OperationTests(OperationTestBase): | ||||
|         second_state = first_state.clone() | ||||
|         operation = migrations.AlterModelTable(name='pony', table=None) | ||||
|         operation.state_forwards(app_label, second_state) | ||||
|         with connection.schema_editor() as editor: | ||||
|         atomic_rename = connection.features.supports_atomic_references_rename | ||||
|         with connection.schema_editor(atomic=atomic_rename) as editor: | ||||
|             operation.database_forwards(app_label, editor, first_state, second_state) | ||||
|         self.assertTableExists(new_m2m_table) | ||||
|         self.assertTableNotExists(original_m2m_table) | ||||
|         # And test reversal | ||||
|         with connection.schema_editor() as editor: | ||||
|         with connection.schema_editor(atomic=atomic_rename) as editor: | ||||
|             operation.database_backwards(app_label, editor, second_state, first_state) | ||||
|         self.assertTableExists(original_m2m_table) | ||||
|         self.assertTableNotExists(new_m2m_table) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user