다음은 models.py입니다 쉘 :갱신 외래 키 항목
알 수있는 바와 같이class UserProfile(models.Model):
user = models.OneToOneField(User)
belongs_to_user_category = models.ForeignKey(UserCustomCategory, null=True, blank=True)
class UserHistory(models.Model):
date_time = models.DateTimeField()
user = models.ForeignKey(UserProfile, null=True, blank=True)
points_earned = models.DecimalField(max_digits=5, decimal_places=3)
이 userhistory는 사용자 프로필에 대한 하나의 foreign 키이다.
from myapp.models import *
uobj = UserProfile.objects.all()
for i in uobj:
if i.user.username[0] == 'a':
b = UserHistory.objects.create(user=i)
b.points_earned = random.random(10, 100)
b.date_time = datetime.datetime.now()
b.save()
나는 또한 동일한 오류 과 내가 함께 b = UserHistory.objects.get_or_create(user=i)
을 시도했다 : 테스트 목적을 위해 내가 이름 a
시작 내가 파이썬 쉘에서 다음 코드를 작성하는 사용자의 지점을 업데이트하고 싶었다 다음과 같은 오류 얻을 : 당신이 장고의 기본 모델 관리자의 create
방법을 사용하면
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (160, 0))
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (13, 0))
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (63, 0))
ERROR: Internal Python error in the inspect module.
Below is the traceback from this internal error.
Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/IPython/ultraTB.py", line 667, in text
locals,formatvalue=var_repr))
File "/usr/lib/python2.6/inspect.py", line 875, in formatargvalues
specs.append(strseq(args[i], convert, join))
File "/usr/lib/python2.6/inspect.py", line 830, in strseq
return convert(object)
File "/usr/lib/python2.6/inspect.py", line 872, in convert
return formatarg(name) + formatvalue(locals[name])
KeyError: 'connection'
IPython's exception reporting continues...
---------------------------------------------------------------------------
IntegrityError Traceback (most recent call last)
IntegrityError: (1048, "Column 'date_time' cannot be null")
사용자 클래스는 어떻게 설정합니까? –