mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #23043: alter_field drops defaults too
This commit is contained in:
		| @@ -766,6 +766,16 @@ class BaseDatabaseSchemaEditor(object): | ||||
|                     "check": new_db_params['check'], | ||||
|                 } | ||||
|             ) | ||||
|         # Drop the default if we need to | ||||
|         # (Django usually does not use in-database defaults) | ||||
|         if not self.skip_default(new_field) and new_field.default is not None: | ||||
|             sql = self.sql_alter_column % { | ||||
|                 "table": self.quote_name(model._meta.db_table), | ||||
|                 "changes": self.sql_alter_column_no_default % { | ||||
|                     "column": self.quote_name(new_field.column), | ||||
|                 } | ||||
|             } | ||||
|             self.execute(sql) | ||||
|         # Reset connection if required | ||||
|         if self.connection.features.connection_persists_old_columns: | ||||
|             self.connection.close() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user