开发者

ValueError: invalid literal for int() with base 10:

i am getting this value error, when i try to insert some data to django model. My python script is :

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() 

My models.py is

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()

Please help me to solve this error as i am 开发者_JAVA技巧new to python programming. The error is "ValueError: invalid literal for int() with base 10: 'John'


Don't use positional arguments, use keywords to specify which field is being populated with what data.

EmployeeDetails(userName=userName, designation=designation) #etc

Also, if you are going to call save() anyways, you can use EmployeeDetails.objects.create(...)


I am no Django expert, but try replacing

EmployeeDetails(userName,designation,employeeID,contactNumber,project,dateOfJoin).save() 

with

EmployeeDetails(userName=userName,designation=designation,employeeID=employeeID,contactNumber=contactNumber,project=project,dateOfJoin=dateOfJoin).save() 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜