0
當我嘗試保存數據時發生錯誤。Django - 列'user_id'不能爲空
列'user_id'不能爲空。
下面是我使用的型號
class XML(models.Model):
nome_destinatario = models.CharField(max_length=255)
cnpj_destinatario = models.CharField(max_length=15)
user = models.ForeignKey(User)
def __str__(self):
return self.nome_destinatario
串行
class XMLCreateSerializer(serializers.ModelSerializer):
class Meta:
model = XML
fields = ('nome_destinatario', 'cnpj_destinatario', 'user_id')
查看設置
xml_create = XMLCreateSerializer(data={'nome_emitente': 'NILVA', 'cnpj_destinatario':'5645654654','user_id': 1})
if xml_create.is_valid():
salvo = xml_create.save()
else:
salvo = xml_create.errors
它的工作!非常感謝你。 –