#26476: Migration preserve_default does not work properly
----------------------------+-----------------------------------------
     Reporter:  madEng84    |      Owner:  nobody
         Type:  Bug         |     Status:  new
    Component:  Migrations  |    Version:  1.8
     Severity:  Normal      |   Keywords:  preserve_default sqlmigrate
 Triage Stage:  Unreviewed  |  Has patch:  0
Easy pickings:  0           |      UI/UX:  0
----------------------------+-----------------------------------------
 Hi all, I'm using Django<1.9
 When i change my model adding a default to one field or adding a new field
 to existing model with a default, and I launch:

 `./manage.py sqlmigrate my_app_label my_migration_name`

 I see:

 ''BEGIN;
 ALTER TABLE `my_app_label` ADD COLUMN `my_char_field` varchar(36) DEFAULT
 test NOT NULL;
 ALTER TABLE `my_app_label` ALTER COLUMN `my_char_field` DROP DEFAULT;
 COMMIT;''

 Reading Docs ([https://docs.djangoproject.com/en/1.8/ref/migration-
 operations/#alterfield]) i can see, about  that ''preserve_default'', that
 :

    The preserve_default argument indicates whether the field’s default
 value is permanent and should be baked into the project state (True), or
 if it is temporary and just for this migration (False) - usually because
 the migration is altering a nullable field to a non-nullable one and needs
 a default value to put into existing rows. It does not affect the behavior
 of setting defaults in the database directly - '''Django never sets
 database defaults and always applies them in the Django ORM code'''.

 So why I see launching sqlmigrate **DEFAULT** and than **DROP DEFAULT** ?
 For large databases this could be an heavy pair of query.

 Best Regards

--
Ticket URL: <https://code.djangoproject.com/ticket/26476>
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 post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.f7d11f0103d19dda5b98a442ac717d88%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to