OperationalError, no such column. Django

后端 未结 22 1673
情话喂你
情话喂你 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:38

    Agree with Rishikesh. I too tried to solve this issue for a long time. This will be solved with either or both of 2 methods-

    1.Try deleting the migrations in the app's migrations folder(except init.py) and then running makemigrations command

    2.If that doesn't work, try renaming the model (this is the last resort and might get a little messy but will work for sure.If django asks "did you rename the model? just press N.").Hope it helps..:)

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-12-24 01:40

    You did every thing correct, I have been gone through same problem. First delete you db and migrations I solved my adding name of my app in makemigrations:

    python manage.py makemigrations appname
    python manage.py migrate
    

    This will definitely work.

    0 讨论(0)
  • 2020-12-24 01:40

    Anyone coming here:

    Remove all migrations Remove db.sqlite file

    redo migrations

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