1
我爲我的django應用程序(django 1.9,python 3.5)使用django-phonenumber-field電池。Django,「無法適應類型錯誤」,Sqlite與Postresql
我有喜歡的形式如下:
class PhoneChangeForm(forms.Form):
phonenumber = PhoneNumberField(widget=PhoneNumberPrefixWidget(attrs={'placeholder': _('Phone number')}),
label=_("Enter phone"))
def clean_phonenumber(self):
users = User.objects.filter(profile__phone__iexact=self.cleaned_data['phonenumber'])
if users.count() == 0:
return self.cleaned_data['phonenumber']
else:
raise forms.ValidationError(_("This phone is already in use."))
在我的開發環境這種形式正常工作。如果有給定電話號碼的用戶,則引發ValidationError。
當我移動相同的代碼投入生產我有以下錯誤:
Django Version: 1.9.6
Exception Type: ProgrammingError
Exception Value: can't adapt type 'PhoneNumber'
創作者沒有到最後的意見作出迴應,所以我決定在這裏問。你可以建議最好的方式來調試它
您是否在生產環境中完成了pip install django-phonenumber-field?您是否使用自定義用戶模型來存儲具有電話號碼的用戶? –
當然,它在! –
如果您在生產環境中使用sqlite3,則會嘗試將其存儲爲字符串。 http://stackoverflow.com/questions/6510529/django-cant-adapt-type-error-using-mutliple-databases-postgresql-8-4-and-sql –