我想允许模型中的所有列都可以为空,当我尝试插入数据时,我会收到以下错误。
invalid literal for int() with base 10: ''
这是我的型号代码:
class Edu_Expense(models.Model):
uin = models.ForeignKey(Claim)
child_id = models.ForeignKey(Child_Info)
edu_receipt = models.CharField(max_length=10,null=True,blank=True)
edu_fees = models.IntegerField(null=True,blank=True)
edu_date = models.DateField(default=None,null=True,blank=True)
entry_receipt = models.CharField(max_length=10,null=True,blank=True)
entry_fees = models.IntegerField(null=True,blank=True)
entry_date = models.DateField(default=None,null=True,blank=True)
lab_receipt = models.CharField(max_length=10,null=True,blank=True)
lab_fees = models.IntegerField(null=True,blank=True)
lab_date = models.DateField(default=None,null=True,blank=True)
other_receipt = models.CharField(max_length=10,null=True,blank=True)
other_fees = models.IntegerField(null=True,blank=True)
other_date = models.DateField(default=None,null=True,blank=True)
prac_receipt = models.CharField(max_length=10,null=True,blank=True)
prac_fees = models.IntegerField(null=True,blank=True)
prac_date = models.DateField(default=None,null=True,blank=True)
instru_receipt = models.CharField(max_length=10,null=True,blank=True)
instru_fees = models.IntegerField(null=True,blank=True)
instru_date = models.DateField(default=None,null=True,blank= True)
lib_receipt = models.CharField(max_length=10,null=True,blank=True)
lib_fees = models.IntegerField(null=True,blank=True)
lib_date = models.DateField(default=None,null=True,blank=True)
sport_receipt = models.CharField(max_length=10,null=True,blank=True)
sport_fees = models.IntegerField(null=True,blank=True)
sport_date = models.DateField(default=None,null=True,blank=True)
coedu_receipt = models.CharField(max_length=10,null=True,blank=True)
coedu_fees = models.IntegerField(null=True,blank=True)
coedu_date = models.DateField(default=None,null=True,blank=True)
board_receipt = models.CharField(max_length=10,null=True,blank=True)
board_fees = models.IntegerField(null=True,blank=True)
board_date = models.DateField(default=None,null=True,blank=True)
books_receipt = models.CharField(max_length=10,null=True,blank=True)
books_fees = models.IntegerField(null=True,blank=True)
books_date = models.DateField(default=None,null=True,blank=True)
notebook_receipt = models.CharField(max_length=10,null=True,blank=True)
notebook_fees = models.IntegerField(null=True,blank=True)
notebook_date = models.DateField(default=None,null=True,blank=True)
uniform_receipt = models.CharField(max_length=10,null=True,blank=True)
uniform_fees = models.IntegerField(null=True,blank=True)
uniform_date = models.DateField(default=None,null=True,blank=True)
shoes_receipt = models.CharField(max_length=10,null=True,blank=True)
shoes_fees = models.IntegerField(null=True,blank=True)
shoes_date = models.DateField(default=None,null=True,blank=True)
vvn_receipt = models.CharField(max_length=10,null=True,blank=True)
vvn_fees = models.IntegerField(null=True,blank=True,)
vvn_date = models.DateField(default=None,null=True,blank=True)
claimed_date = models.DateField(default=None,blank=True,null=True)
tot_claim_fees = models.IntegerField(null=True,blank=True)
status = models.CharField(max_length=10,null=True,blank=True)
这是我的模特。任何帮助将不胜感激。
答案 0 :(得分:0)
您可以通过输入以下内容在python控制台中复制此错误:
int('')
> ValueError: invalid literal for int() with base 10: ''
因此,通过这些新发现的知识,我们可以进一步诊断您的问题。
我猜您在应用程序中使用的是模型表单(可能带有验证),这意味着当您提交表单时,django会通过空字符串''
。此时,IntegerField
的值未定义为null/None
,而''
正在传递给您的模型,而该模型无法将其转换为整数。
因此您看到错误消息:
ValueError: invalid literal for int() with base 10: ''
如果您在表单周围显示代码,我们可能会进一步提供帮助。