简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM