ValueError:以 10 为基数的 int() 的文字无效:

发布于 2024-10-19 16:13:52 字数 871 浏览 1 评论 0原文

当我尝试将一些数据插入 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吃兔兔 2024-10-26 16:13:52

不要使用位置参数,使用关键字来指定哪个字段将填充哪些数据。

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

另外,如果您无论如何都要调用 save(),则可以使用 EmployeeDetails.objects.create(...)

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

海拔太高太耀眼 2024-10-26 16:13:52

我不是 Django 专家,但尝试替换

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

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

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() 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文