#33413: Errors with db_collation – no propagation to foreignkeys
----------------------------+------------------------------------
     Reporter:  typonaut    |                    Owner:  nobody
         Type:  Bug         |                   Status:  new
    Component:  Migrations  |                  Version:  3.2
     Severity:  Normal      |               Resolution:
     Keywords:              |             Triage Stage:  Accepted
    Has patch:  0           |      Needs documentation:  0
  Needs tests:  0           |  Patch needs improvement:  0
Easy pickings:  0           |                    UI/UX:  0
----------------------------+------------------------------------
Changes (by Simon Charette):

 * component:  Database layer (models, ORM) => Migrations
 * stage:  Unreviewed => Accepted


Comment:

 
[https://github.com/django/django/blob/806efe912b846c1fde250c9321d8334b7517cd56/django/db/backends/base/schema.py#L217-L219
 It seems like] this should be addressable by defining a
 `ForeignKey.db_collation` property that proxies
 `self.target_field.db_column`

 {{{#!diff
 diff --git a/django/db/models/fields/related.py
 b/django/db/models/fields/related.py
 index 11407ac902..f82f787f5c 100644
 --- a/django/db/models/fields/related.py
 +++ b/django/db/models/fields/related.py
 @@ -1043,6 +1043,10 @@ def db_type(self, connection):
      def db_parameters(self, connection):
          return {"type": self.db_type(connection), "check":
 self.db_check(connection)}

 +    @property
 +    def db_collation(self):
 +        return getattr(self.target_field, 'db_collation', None)
 +
      def convert_empty_strings(self, value, expression, connection):
          if (not value) and isinstance(value, str):
              return None
 }}}

 I do wonder if it would be better to have `'collation': self.db_collation`
 returned in `CharField` and `TextField.db_params` instead and adapt
 `ForeignKey.db_params` to simply proxy `self.target_feld.db_params` and
 adapt the schema editor to branch of `params['collation']` instead as
 `db_collation` is pretty much a ''text fields'' option that ''related
 fields'' should know nothing about.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33413#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.1a85a67c61c38e89b4ed96efb425f627%40djangoproject.com.

Reply via email to