#33192: It is not possible to use a custom lookup/transorm in a CheckConstraint
-------------------------------------+-------------------------------------
     Reporter:  Fabien MICHEL        |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  3.1
  (models, ORM)                      |               Resolution:
     Severity:  Normal               |  worksforme
     Keywords:  lookup, transform,   |             Triage Stage:
  CheckContraint, migrate            |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

 > In this case, won't I expose my migration to use code that could be
 ananchronic if the code of the custom lookup changes after the migration
 has been created? Is it not better to embed the custom lookup on the
 migration which create the constraint in database ?

 The migration framework doesn't detect change at the resulting SQL level
 so if you were to change your lookup logic you'd have to manually create a
 migration that removes and adds back the new constraint. Nothing prevents
 you from defining the lookup in two locations though (`ready()`) and in
 the migration itself so it's already there and only overrides the project
 specific lookup when the migration file is loaded. Just keep in mind that
 Django won't be hand holding you if you change the SQL generated by the
 lookup.

 In a sense this is similar to how Django allows you to add and remove
 managers to your model definition without 'baking' the manage definition
 in the migration file; since the migration framework holds 'references' of
 managers and lookups it's your responsibility to keep 'referenced values'
 coherent with migration states.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33192#comment:8>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/071.41226b97eb186fdf7727cc62b1ed5267%40djangoproject.com.

Reply via email to