Skip to content
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

Closed
jeffbowen opened this issue Aug 16, 2014 · 4 comments
Closed

Can't run South migration to add a PhoneNumberField #41

jeffbowen opened this issue Aug 16, 2014 · 4 comments

Comments

@jeffbowen
Copy link
Contributor

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 the to_python function changes value from "" to None 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 "" and None 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!

@jeffbowen jeffbowen mentioned this issue Aug 16, 2014
@saadbinakhlaq
Copy link

not fixed :(

@MattBlack85
Copy link

same here while running migrate command

@ApsOps
Copy link

ApsOps commented Nov 4, 2014

@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
@LennyLip
Copy link

LennyLip commented May 7, 2015

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants