[英]Why am I getting a IntegrityError at, null value in a column that doesn't exists... Django
I am trying to hit an external api, when a user submits a form.当用户提交表单时,我正在尝试访问外部 api。 I am using Django and Postgresql
我正在使用 Django 和 Postgresql
My Model我的 Model
class League_Mod(models.Model):
host = models.CharField(max_length=50)
Espn_League_Id = models.IntegerField(unique = True)
Espn_S2 = models.CharField(max_length=3000)
Espn_Swid = models.CharField(max_length=300)
bigdata = models.JSONField(default=dict,null=True)
My Serializer我的序列化器
class Meta:
model = League_Mod
fields = ['host', 'Espn_League_Id','Espn_S2','Espn_Swid','bigdata']
Views意见
where Owners is a large dictionary. Owners 是一个大字典。
league_data = {
'host' : request.data['host'],
'Espn_League_Id' :request.data['Espn_League_Id'],
'Espn_S2' : request.data['Espn_S2'],
'Espn_Swid' : request.data['Espn_Swid'],
'bigdata' : Owners
}
serializer = LeagueSerializer(data=league_data)
print(serializer)
if serializer.is_valid(raise_exception=True):
serializer.save()
return Response(serializer.data)
my print serializer runs, and prints the data correctly.我的打印序列化程序运行,并正确打印数据。
But I get an error:但我收到一个错误:
integrityError at /wel/
null value in column "hello" of relation "api_league_mod" violates not-null constraint
DETAIL: Failing row contains (11, JPFL, 216415, AEAylLD7uSQQ7%2BenPr6av1H%2Fx0Hqbbpn8Jvr91ngxM1ll5ynO685mhN%2BSu..., {D19D67CA-C981-4CA2-8463-AF4111D2E8E2}, {"Person1": {"2010": [0, 1, 2, 2, 2, 3, 3, 3, 3, 4, 5, 5, 6,..., null).
I am very unclear where the column hello is... and there is no relation to api_league_mod Model, so don't quite understand why my serializer is returning unvalid我很不清楚 hello 列在哪里......并且与 api_league_mod Model 没有关系,所以不太明白为什么我的序列化程序返回无效
Any insight would be appreciated.任何见解将不胜感激。 Thanks
谢谢
The column hello
is probably present in the database, which means it was in your League_Mod
model and was removed later.列
hello
可能存在于数据库中,这意味着它在您的League_Mod
model 中,后来被删除。 This removal however is not reflected in any of your migrations.但是,此删除不会反映在您的任何迁移中。
You could try to run manage.py makemigrations
and check the output, it might create the delete operation for the hello
field.您可以尝试运行
manage.py makemigrations
并检查 output,它可能会为hello
字段创建删除操作。
Then run manage.py migrate
to apply the changes to the DB然后运行
manage.py migrate
将更改应用到数据库
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.