加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

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

发布时间:2020-12-20 12:17:49 所属栏目:Python 来源:网络整理
导读:当我尝试将一些数据插入 django模型时,我得到此值错误.我的 python脚本是: from task.employeeDetails.models import EmployeeDetailsdef dumpdata(): userName = "John" designation = 'Software Engineer' employeeID = 2312 contactNumber = 9495321257
当我尝试将一些数据插入 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:int()的无效文字,基数为10:’John’

解决方法

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

EmployeeDetails(userName,dateOfJoin).save()

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读