简体   繁体   English

为什么我在不存在的列中出现 IntegrityError,null 值... Django

[英]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.

相关问题 Django-为什么会出现此IntegrityError:NOT Null约束失败:Restaurants_restaurantlocation.owner_id? - Django - Why am I getting this IntegrityError: NOT Null constraint failed: restaurants_restaurantlocation.owner_id? 为什么我收到IntegrityError:NOT NULL约束失败 - Why am I getting IntegrityError: NOT NULL constraint failed django.db.utils.IntegrityError:列中的值为空-但值不为空 - django.db.utils.IntegrityError: null value in column - but value is not null IntegrityError-列不能为空DJANGO - IntegrityError - Column cannot be null DJANGO 我收到 django 的 IntegrityError UNIQUE 约束失败 - I am getting a IntegrityError UNIQUE constraint failed for django 提交表单时,为什么Django在“ user_id”列中引发IntegrityError:null值违反了非null约束? - Why does Django raised IntegrityError :null value in column “user_id” violates not-null constraint when a form is committed? 尝试导入JSON时为什么会收到IntegrityError? - Why am I getting an IntegrityError when attempting to import JSON? python django 中 /***/ (1048, "Column '***' cannot be null") 处的 IntegrityError - IntegrityError at /***/ (1048, "Column '***' cannot be null") in python django 为什么会出现KeyError:“ Django设置未定义RESOLVER”? - Why am I getting KeyError: “Django settings doesn't define RESOLVER”? django.db.utils.IntegrityError:“地址”列中的空值违反了非空约束 - django.db.utils.IntegrityError: null value in column “address” violates not-null constraint
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM