OperationalError, no such column. Django

后端 未结 22 1832
情话喂你
情话喂你 2020-12-24 00:45

I am very new to django and was able to finish the tutorial on djangoproject.com without any errors. I am now going through the Django REST framework tutorial found at http:

22条回答
  •  借酒劲吻你
    2020-12-24 01:39

    If your issue is like mine, then this a workaround. The good news is that you wont have to delete your db.

    Check that there isn't some other model that uses this model as a reference.

    django.db.utils.OperationalError: no such column: parts_part_type.blah
    

    This was only happening to me because I had another model called "product" in a different app called "products" that referenced this model.

    part = models.ForeignKey("parts.Part", related_name="some part", limit_choices_to={'part_type':Part_Type.objects.get(prefix='PART')},)
    

    My solution was:

    1. comment out the other app (in this case prodcuts) from settings.py
    2. python manage.py makemigrations; python manage.py migrate
    3. un-comment the other app so its enabled again.
    4. python manage.py makemigrations; python manage.py migrate

    Technically I think I need to change the limit_choices_to reference so

提交回复
热议问题