Opened 11 months ago

Last modified 11 months ago

#35019 closed Bug

GeneratedField save error — at Version 2

Reported by: Deb Kumar Das Owned by: nobody
Component: Database layer (models, ORM) Version: 5.0
Severity: Release blocker Keywords: GeneratedField save error
Cc: Lily Foote, Jeremy Nauta Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Deb Kumar Das)

When using GeneratedField column along with a ForeignKey column, getting error while saving.
The below model throws error while saving data from admin panel.

class Square(models.Model):
    side = models.IntegerField()
    area = models.GeneratedField(
        expression=F("side") * F("side"),
        output_field=models.BigIntegerField(),
        db_persist=True,
    )
    user = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)

Throws the below error

Cannot force an update in save() with no primary key.

Change History (3)

by Deb Kumar Das, 11 months ago

Attachment: django_error.PNG added

comment:1 by Deb Kumar Das, 11 months ago

Component: UncategorizedDatabase layer (models, ORM)

comment:2 by Deb Kumar Das, 11 months ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top