1. Matthew Schinckel
  2. django-jsonfield
  3. Issues
Issue #27 wontfix

South migration doesn't set fields default value

Russell Sim
created an issue

I'm having a problem when using django 1.6 south 0.8.4 if i create a new field, the default value fails to be set during the migration.

with a field with a definition like

    extra_data = JSONField(help_text='Datastore specific values should be stored in this field.')

the south generated code is

        # Adding field 'Group.extra_data'
        db.add_column(u'people_group', 'extra_data',
                      self.gf('jsonfield.fields.JSONField')(default={}),
                      keep_default=False)

once i run the migration i can't see the default value being set, and this also causes a validition error when querying the models.

MariaDB [(none)]> select * from karaage_dev.people_group;                                              
+----+-------+--------------------------------+------------+------------+
| id | name  | description                    | foreign_id | extra_data |
+----+-------+--------------------------------+------------+------------+
|  1 | dummy | Dummy group used for upgrades. | NULL       |            |
+----+-------+--------------------------------+------------+------------+
1 row in set (0.00 sec)

Comments (5)

  1. Russell Sim reporter

    so i have done some debugging, seem that mysql doesn't support default values for text columns. http://bugs.mysql.com/bug.php?id=21532 this is why south is ignoring the default value.

    so i don't think that it's worth trying to fix this migration problem.

    i have found a workaround, by allowing null and blank.

        extra_data = JSONField(null=True, blank=True,
                               help_text='Datastore specific values should be stored in this field.')
    

    thanks for your quick reply!

  2. Log in to comment