Closed alepn closed 3 years ago
It’s hard to know what might be causing that problem if you don’t post a piece of code which you think it might be causing that error, so please do.
class Profile(models.Model):
name = models.CharField('Name', max_length=80)
class Email(models.Model):
profile = models.ForeignKey(Profile)
email = models.CharField('Email', max_length=80, unique=True)
from django_restql.mixins import DynamicFieldsMixin
from django_restql.serializers import NestedModelSerializer
class EmailSerializer(DynamicFieldsMixin, NestedModelSerializer):
class Meta:
model = Email
fields = ['profile','email']
class ProfileSerializer(DynamicFieldsMixin, NestedModelSerializer):
email_set = NestedField(EmailSerializer, many=True, required=False, allow_null=True)
class Meta:
model = Email
fields = ['name','email_set']
If you send a request with a existing email, it will fail because the unique constraint. If you resend the request with another e-mail, it show a fk constraint error, because profile_id on nested email_set was lost. Tested with django-restql versions: 0.10.2 and 0.11.2
After a validation from model (ex.: unique field violate), I cannot send the request again.
It causes a constraint error:
null value in column "foo_id" violates not-null constraint