Django relation error when running make migrations

前端 未结 1 1951
野性不改
野性不改 2021-01-15 17:17

Hey I am attempting to initialize a new database, but I am running into some issues setting up the migrations. The error I am getting appears to stem from setting up my form

1条回答
  •  星月不相逢
    2021-01-15 18:22

    You cannot execute queries during the initialization of the app registry. Your choices.py file is indirectly imported during this time, resulting in the error. To fix this issue, you can pass a callable to choices:

    def get_provinces():
        province_choices = []
        for province in ProvinceCode.objects.filter(country_code_id=1).order_by('code'):
            province_choices.append((province.code, province.code))
        return province_choices
    
    class MemberForm(forms.Form):
        provinces = forms.ChoiceField(label='Provinces', choices=get_provinces, required=True)
    

    0 讨论(0)
提交回复
热议问题