当我尝试将一些数据插入django模型时,我得到此值错误。我的python脚本是:
from task.employeeDetails.models import EmployeeDetails
def dumpdata():
userName = "John"
designation = 'Software Engineer'
employeeID = 2312
contactNumber = 9495321257
project = 'AOL'
dateOfJoin = '2009-10-10'
EmployeeDetails(userName,designation,employeeID,contactNumber,project,dateOfJoin).save()
dumpdata()
我的models.py是
class EmployeeDetails(models.Model):
userName = models.CharField(max_length=200)
designation = models.CharField(max_length=200)
employeeID = models.IntegerField()
contactNumber = models.CharField(max_length=200)
project = models.CharField(max_length=200)
dateOfJoin=models.TextField()
请帮我解决这个错误,因为我是python编程的新手。错误是“ValueError:int()的无效文字,基数为10:'John'
答案 0 :(得分:7)
不要使用位置参数,使用关键字指定使用哪些数据填充哪个字段。
EmployeeDetails(userName=userName, designation=designation) #etc
另外,如果您要打电话save()
,可以使用EmployeeDetails.objects.create(...)
答案 1 :(得分:5)
我不是Django专家,但尝试替换
EmployeeDetails(userName,designation,employeeID,contactNumber,project,dateOfJoin).save()
与
EmployeeDetails(userName=userName,designation=designation,employeeID=employeeID,contactNumber=contactNumber,project=project,dateOfJoin=dateOfJoin).save()