1
私はdjango-phonenumber-fieldバッテリーを私のdjangoアプリ(django 1.9、python 3.5)に使用しています。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'
クリエイターは、最後のコメントに反応しない:私はエラーを次しているプロダクションに同じコードを移動してい
。
実稼働環境でdjango-phonenumber-fieldをpip installしましたか?あなたはphonenumberでユーザーを格納するカスタムユーザーモデルを使用していますか? –
確かに、それです! –
実稼働環境でsqlite3を使用している場合は、sqlite3を文字列として格納しようとします。 http://stackoverflow.com/questions/6510529/django-cant-adapt-type-error-using-mutliple-databases-postgresql-8-4-and-sql –