project = models.ForeignKey("Project", on_delete=models.CASCADE)
health = models.CharField(
choices=HEALTH.choices, max_length=50, default=HEALTH.GREEN,
db_default=HEALTH.GREEN
)
health_value = models.GeneratedField(
expression=Case(
When(health=HEALTH.GREEN, then=Value(1)),
When(health=HEALTH.YELLOW, then=Value(2)),
When(health=HEALTH.RED, then=Value(3)),
default=Value(0),
),
output_field=models.IntegerField(),
db_persist=True,
)
}}}
In this simple model when I try to create a new **ProjectHealth** record,
**health_value** is set as a deferred field in base save(). This causes
the rest of the save process to treat this as an update instead of an
insert. It ends with the error ''Cannot force an update in save() with no
primary key.''
--
Ticket URL: <https://code.djangoproject.com/ticket/35027>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => duplicate
Comment:
Duplicate of #35019, will be fixed in Django 5.0.1 expected to be released
on Jan 2nd.
--
Ticket URL: <https://code.djangoproject.com/ticket/35027#comment:1>