-
Notifications
You must be signed in to change notification settings - Fork 317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't run South migration to add a PhoneNumberField #41
Comments
Merged
not fixed :( |
same here while running migrate command |
@stefanfoulis Hi! Do you plan to merge the fix PR soon? |
jeffbowen
added a commit
to jeffbowen/django-phonenumber-field
that referenced
this issue
Nov 4, 2014
same error, if we try to get instance with no char: like Phone.objects.get(phone=8909999999) or just Phone.objects.get(phone=1) |
thedrow
added a commit
that referenced
this issue
Nov 30, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm adding a PhoneNumberField field (with blank=True) to an existing model. As such, when I run
./manage schemamigration --auto myapp
, South demands that I provide a default value for the column it will be adding. If I set the default (either in models.py or as a one-off in the South migration) to""
(an empty string), when I try to run the migration I get an AttributeError:AttributeError: 'NoneType' object has no attribute 'as_e164'
This is because in
get_prep_value
, the first if block is passed (since""
does not equal None) and theto_python
function changes value from "" toNone
so when line 67 is hit, we get the AttributeError.If I try setting the default to
None
, I then get an IntegrityError:django.db.utils.IntegrityError: column "phone_number" contains null values
As the Django docs recommend and as mentioned in issue 1, we should use an empty string, not null, to represent a blank value for a CharField (which PhoneNumberField is under the hood). As such, although adding
null=True
to the field definition in my models makes the migration succeed, it leads to trouble down the road as you can end up with both""
andNone
as null values.Not sure exactly how or where you'd like to change things but the request is that it be possible to have South work properly when defining a PhoneNumberField with blank=True. Let me know if I'm misunderstanding something here. Thanks!
The text was updated successfully, but these errors were encountered: