【问题标题】:How to rectify Django Integrity Error while creating a nested serializer?如何在创建嵌套序列化程序时纠正 Django 完整性错误?
【发布时间】:2022-11-23 03:10:12
【问题描述】:

出现完整性错误 as shown in job `


class JobSerializer(ModelSerializer):
    company = CompanySerializer(read_only=True)
    skills = SkillSerializer(many=True, read_only=True)

    class Meta:
        fields = ['title', 'description', 'max_salary', 'min_salary', 'employment_type', 'max_experience',
                  'min_experience', 'company', 'location', 'industry_type', 'skills']
        model = Job


`

嵌套序列化程序出现此错误 ` Django 版本:4.1.3 异常类型:IntegrityError 异常值:
NOT NULL 约束失败:naukriapp_job.company_id 异常位置:D:\naukri\naukrienv\lib\site-packages\django\db\backends\sqlite3\base.py, line 357, in execute 在以下期间提出:naukriapp.views.Jobviewset Python 可执行文件:D:\naukri\naukrienv\Scripts\python.exe

` 我需要纠正这个完整性错误

【问题讨论】:

    标签: serialization django-rest-framework nested elixir-jason


    【解决方案1】:

    请修改您使用外键的模型。

    jobs = models.ForeignKey(Job,default=True, on_delete=models.SET_DEFAULT)

    通过遵循上述方法,完整性问题将得到解决。

    【讨论】:

      猜你喜欢
      • 2019-01-29
      • 1970-01-01
      • 1970-01-01
      • 2015-06-01
      • 2015-04-17
      • 1970-01-01
      • 2020-07-07
      • 2017-03-12
      • 2015-06-18
      相关资源
      最近更新 更多