我在django-2中编写了这个简单的模型,当我尝试迁移时,我得到了
ValueError:以10为底的int()无效文字:
from django.db import models
class Teacher(models.Model):
name = models.CharField(max_length=50)
user = models.IntegerField(default='',blank=True)
passcode = models.IntegerField(default='',blank=True)
def __str__(self):
return self.name
class Student(models.Model):
name = models.CharField(max_length=50)
user = models.IntegerField(default='', blank=True)
passcode = models.IntegerField(default='', blank=True)
teacher = models.ManyToManyField(Teacher)
def __str__(self):
return self.name
class Lesson (models.Model):
name = models.CharField(max_length=50)
cource = models.IntegerField(default='', blank=True)
teacher = models.ForeignKey("Teacher", on_delete=models.CASCADE)
Student = models.ManyToManyField(Student)
def __str__(self):
return self.name
class Score(models.Model):
score = models.FloatField(default='', blank=True)
student = models.ForeignKey(Student, on_delete=models.CASCADE)
lesson = models.ForeignKey(Lesson, on_delete=models.CASCADE)
答案 0 :(得分:2)
IntegerField
和FloatField
的默认值不能为字符串。
default=''
表示空字符串。
将IntegerField
和FloatField
的默认值更改为某个数字或设置null=True
:
示例:
# Means it can not be empty and if it received empty, put 0 instead.
score = models.FloatField(default=0, blank=True)
或
# Means it is okay to be empty.
score = models.FloatField(null=True, blank=True)
此外,您可能需要删除迁移文件以进行以前的更改。