mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[4.0.x] Fixed #33194 -- Fixed migrations when altering a field with functional indexes/unique constraints on SQLite.
This adjusts Expressions.rename_table_references() to only update alias when needed. Regression in83fcfc9ec8. Co-authored-by: Simon Charette <charettes@users.noreply.github.com> Backport of86971c4090from main
This commit is contained in:
		
				
					committed by
					
						 Mariusz Felisiak
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							f5fd03aebe
						
					
				
				
					commit
					00aa3e0b9b
				
			| @@ -5,6 +5,7 @@ from django.db.backends.ddl_references import ( | ||||
| from django.db.models import ExpressionList, F | ||||
| from django.db.models.functions import Upper | ||||
| from django.db.models.indexes import IndexExpression | ||||
| from django.db.models.sql import Query | ||||
| from django.test import SimpleTestCase, TransactionTestCase | ||||
|  | ||||
| from .models import Person | ||||
| @@ -229,6 +230,27 @@ class ExpressionsTests(TransactionTestCase): | ||||
|             str(self.expressions), | ||||
|         ) | ||||
|  | ||||
|     def test_rename_table_references_without_alias(self): | ||||
|         compiler = Query(Person, alias_cols=False).get_compiler(connection=connection) | ||||
|         table = Person._meta.db_table | ||||
|         expressions = Expressions( | ||||
|             table=table, | ||||
|             expressions=ExpressionList( | ||||
|                 IndexExpression(Upper('last_name')), | ||||
|                 IndexExpression(F('first_name')), | ||||
|             ).resolve_expression(compiler.query), | ||||
|             compiler=compiler, | ||||
|             quote_value=self.editor.quote_value, | ||||
|         ) | ||||
|         expressions.rename_table_references(table, 'other') | ||||
|         self.assertIs(expressions.references_table(table), False) | ||||
|         self.assertIs(expressions.references_table('other'), True) | ||||
|         expected_str = '(UPPER(%s)), %s' % ( | ||||
|             self.editor.quote_name('last_name'), | ||||
|             self.editor.quote_name('first_name'), | ||||
|         ) | ||||
|         self.assertEqual(str(expressions), expected_str) | ||||
|  | ||||
|     def test_rename_column_references(self): | ||||
|         table = Person._meta.db_table | ||||
|         self.expressions.rename_column_references(table, 'first_name', 'other') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user