Upgrading from Django 1.6 to 1.9: python manage.py migrate failure

前端 未结 1 872
北荒
北荒 2020-12-20 19:48

I\'m running Django 1.6.6 on production and have recently upgraded to 1.9.7 on staging (dev server). This update was performed on the server and I followed the steps outline

相关标签:
1条回答
  • 2020-12-20 20:19

    The problem is that your queryset is being evaluated when the urls.py loads. When you run makemigrations for a new project, this causes the error because the table has not been created yet.

    You can fix this by subclassing ListView and moving the queryset into get_queryset.

    class MyListView(ListView):
        template_name = 'numeric/apply.html'
    
        def get_queryset(self):
            return list(chain(models.HowToApply.objects.filter(active=True).order_by('sequence_number'), models.AcademyAdmin.objects.all()))
    

    Then change your url pattern to use your new view.

    url(r'^academy/howtoapply/$',
        MyListView.as_view(),
        name='apply',
    ),
    

    Django 1.9 runs some checks to validate your url patterns, which means that the url patterns are loaded before the makemigrations command runs. Django 1.8 does not have these checks, so you can get away with setting the queryset as you have done.

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