我想在我的models.py文件中創建外鍵。但是在運行python manage.py migrate命令時,我得到了下面的錯誤,以前每一件事情都很好。即使我已經撤消了所有的改變,它仍然給出同樣的錯誤,我也嘗試刪除我的數據庫,但沒有任何工作。ValueError:相關模型u'mutech.branch'無法解析
Applying mutech.0004_sub_branch...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/rahul/mydjangoapp/jango/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
.
.
.
.
.
File "/home/rahul/mydjangoapp/jango/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1414, in resolve_related_fields
raise ValueError('Related model %r cannot be resolved' % self.rel.to)
ValueError: Related model u'mutech.branch' cannot be resolved
models.py file-
from django.db import models
class branch(models.Model):
branch_title = models.CharField(max_length=50)
def __unicode__(self): # __str__ on Python 3
return str(self.branch_title)
class project(models.Model):
project_title = models.CharField(max_length=50)
project_image = models.ImageField(upload_to="images")
project_desc = models.CharField(max_length=200)
project_duration = models.CharField(max_length=50)
branch = models.ForeignKey(branch)
def __unicode__(self): # __unicode__ on Python 2
return str(self.project_title)
view.py file is -
from django.shortcuts import render, get_object_or_404, render_to_response
from django.http import HttpResponse, HttpResponseRedirect
from mutech.models import *
def project_info(request):
project_list = project.objects.all()
branch_list = branch.objects.all()
context = {'project_list':project_list , 'branch_list':branch_list }
return render(request, 'mutech/project.html', context)
def project_branch_info(request):
branch_list = branch.objects.all()
context = {'branch_list':branch_list }
return render(request, 'mutech/project_branch_info.html', context)
檢查,如果存在與名稱分支另一VAR /手動模式調整嘗試依賴,還,U應當使用大寫字母。科。 – levi
感謝您的回答,但model.py文件中只有一個分支類別 –
您可以發佈您的遷移文件嗎? – knbk