Refs #33413 -- Added collation to CharField/TextField's db_parameters.
This commit is contained in:
parent
aa28c392b9
commit
87da283338
|
@ -275,10 +275,11 @@ class BaseDatabaseSchemaEditor:
|
||||||
|
|
||||||
# Field <-> database mapping functions
|
# Field <-> database mapping functions
|
||||||
|
|
||||||
def _iter_column_sql(self, column_db_type, params, model, field, include_default):
|
def _iter_column_sql(
|
||||||
|
self, column_db_type, params, model, field, field_db_params, include_default
|
||||||
|
):
|
||||||
yield column_db_type
|
yield column_db_type
|
||||||
collation = getattr(field, "db_collation", None)
|
if collation := field_db_params.get("collation"):
|
||||||
if collation:
|
|
||||||
yield self._collate_sql(collation)
|
yield self._collate_sql(collation)
|
||||||
# Work out nullability.
|
# Work out nullability.
|
||||||
null = field.null
|
null = field.null
|
||||||
|
@ -335,8 +336,8 @@ class BaseDatabaseSchemaEditor:
|
||||||
had set_attributes_from_name() called.
|
had set_attributes_from_name() called.
|
||||||
"""
|
"""
|
||||||
# Get the column's type and use that as the basis of the SQL.
|
# Get the column's type and use that as the basis of the SQL.
|
||||||
db_params = field.db_parameters(connection=self.connection)
|
field_db_params = field.db_parameters(connection=self.connection)
|
||||||
column_db_type = db_params["type"]
|
column_db_type = field_db_params["type"]
|
||||||
# Check for fields that aren't actually columns (e.g. M2M).
|
# Check for fields that aren't actually columns (e.g. M2M).
|
||||||
if column_db_type is None:
|
if column_db_type is None:
|
||||||
return None, None
|
return None, None
|
||||||
|
@ -345,7 +346,12 @@ class BaseDatabaseSchemaEditor:
|
||||||
" ".join(
|
" ".join(
|
||||||
# This appends to the params being returned.
|
# This appends to the params being returned.
|
||||||
self._iter_column_sql(
|
self._iter_column_sql(
|
||||||
column_db_type, params, model, field, include_default
|
column_db_type,
|
||||||
|
params,
|
||||||
|
model,
|
||||||
|
field,
|
||||||
|
field_db_params,
|
||||||
|
include_default,
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
params,
|
params,
|
||||||
|
@ -908,8 +914,8 @@ class BaseDatabaseSchemaEditor:
|
||||||
old_type_suffix = old_field.db_type_suffix(connection=self.connection)
|
old_type_suffix = old_field.db_type_suffix(connection=self.connection)
|
||||||
new_type_suffix = new_field.db_type_suffix(connection=self.connection)
|
new_type_suffix = new_field.db_type_suffix(connection=self.connection)
|
||||||
# Collation change?
|
# Collation change?
|
||||||
old_collation = getattr(old_field, "db_collation", None)
|
old_collation = old_db_params.get("collation")
|
||||||
new_collation = getattr(new_field, "db_collation", None)
|
new_collation = new_db_params.get("collation")
|
||||||
if old_collation != new_collation:
|
if old_collation != new_collation:
|
||||||
# Collation change handles also a type change.
|
# Collation change handles also a type change.
|
||||||
fragment = self._alter_column_collation_sql(
|
fragment = self._alter_column_collation_sql(
|
||||||
|
|
|
@ -1182,6 +1182,11 @@ class CharField(Field):
|
||||||
return connection.ops.cast_char_field_without_max_length
|
return connection.ops.cast_char_field_without_max_length
|
||||||
return super().cast_db_type(connection)
|
return super().cast_db_type(connection)
|
||||||
|
|
||||||
|
def db_parameters(self, connection):
|
||||||
|
db_params = super().db_parameters(connection)
|
||||||
|
db_params["collation"] = self.db_collation
|
||||||
|
return db_params
|
||||||
|
|
||||||
def get_internal_type(self):
|
def get_internal_type(self):
|
||||||
return "CharField"
|
return "CharField"
|
||||||
|
|
||||||
|
@ -2361,6 +2366,11 @@ class TextField(Field):
|
||||||
)
|
)
|
||||||
return errors
|
return errors
|
||||||
|
|
||||||
|
def db_parameters(self, connection):
|
||||||
|
db_params = super().db_parameters(connection)
|
||||||
|
db_params["collation"] = self.db_collation
|
||||||
|
return db_params
|
||||||
|
|
||||||
def get_internal_type(self):
|
def get_internal_type(self):
|
||||||
return "TextField"
|
return "TextField"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue