Skip to content

Instantly share code, notes, and snippets.

@sunliwen
Last active December 22, 2015 08:49
Show Gist options
  • Save sunliwen/6447805 to your computer and use it in GitHub Desktop.
Save sunliwen/6447805 to your computer and use it in GitHub Desktop.
how to make south aware of custom field
"""
Following error will occur if there's custom field.
```
! Cannot freeze field 'myapp.mymodel.entity_type'
! (this field has class myapp.fields.EntityTypeField)
! South cannot introspect some fields; this is probably because they are custom
! fields. If they worked in 0.6 or below, this is because we have removed the
! models parser (it often broke things).
! To fix this, read http://south.aeracode.org/wiki/MyFieldsDontWork
```
Simply add the following lines to make south aware of the custom field.
"""
from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["^myapp\.fields\.EntityTypeField"])
class EntityTypeField(models.Field):
def __init__(self, max_length=10, *args, **kwargs):
kwargs['max_length'] = max_length
super(EntityTypeField, self).__init__(*args, **kwargs)
def db_type(self, connection):
return 'char(%s)' % self.max_length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment