本文介绍了ValueError:int()以10为底的无效文字:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试向django模型中插入一些数据时,出现此值错误.我的python脚本是:
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()
我的models.py是
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()
由于我是python编程的新手,请帮助我解决此错误.错误为"ValueError:以10为基数的int()的无效文字:'John'
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'
推荐答案
我不是Django专家,但请尝试替换
I am no Django expert, but try replacing
EmployeeDetails(userName,designation,employeeID,contactNumber,project,dateOfJoin).save()
使用
EmployeeDetails(userName=userName,designation=designation,employeeID=employeeID,contactNumber=contactNumber,project=project,dateOfJoin=dateOfJoin).save()
这篇关于ValueError:int()以10为底的无效文字:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!