从Django模型中删除null = True CharField是更新为空字符串的值

时间:2016-10-19 20:44:32

标签: python django django-models django-rest-framework

导航到我的ListCreateAPIView基本网址时出现错误:

url(r'^tests/$', TestList.as_view())

错误:

coercing to Unicode: need string or buffer, NoneType found

我认为在我的各种模型中,我的很多CharField都与null = True相关。尝试添加时遇到此错误 Django Rest Framework Parsers对于像这样的ListAPIView:

class TestList(generics.ListCreateAPIView):
    """
    """

    queryset = Tests.objects.all()
    serializer_class = TestSerializer
    filter_class = TestFilter
    parser_classes = (FormParser, MultiPartParser)

class Courses(models.Model):
    created = models.DateTimeField(default=timezone.now)
    name = models.CharField(max_length=200, unique=True)
    test = models.ForeignKey('Tests',
                             blank=True,
                             null=True,
                             on_delete=models.CASCADE)


class Tests(models.Model):
    name = models.CharField(max_length=200)
由于CharField上的null = True,或者因为测试外键我不完全确定,它是否会感到沮丧?将删除null = True并迁移解决此问题?另外,我应该删除CharField上的null = True,那么会在数据库中追溯更新吗?

0 个答案:

没有答案