ValueError:以 10 为基数的 int() 的文字无效:
当我尝试将一些数据插入 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:以 10 为基数的 int() 的文字无效:'John'
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'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要使用位置参数,使用关键字来指定哪个字段将填充哪些数据。
另外,如果您无论如何都要调用
save()
,则可以使用EmployeeDetails.objects.create(...)
Don't use positional arguments, use keywords to specify which field is being populated with what data.
Also, if you are going to call
save()
anyways, you can useEmployeeDetails.objects.create(...)
我不是 Django 专家,但尝试替换
为
I am no Django expert, but try replacing
with