Model with GeneratedField and ForeignKey raises an error on save().
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.
attached error screenshot
Change History
(12)
Component: |
Uncategorized → Database layer (models, ORM)
|
Description: |
modified (diff)
|
Description: |
modified (diff)
|
Cc: |
Lily Foote Jeremy Nauta added
|
Severity: |
Normal → Release blocker
|
Summary: |
GeneratedField save error → Model with GeneratedField and ForeignKey raises an error on save().
|
Triage Stage: |
Unreviewed → Accepted
|
Has patch: |
set
|
Needs documentation: |
set
|
Owner: |
changed from nobody to Sarah Boyce
|
Status: |
new → assigned
|
Needs tests: |
set
|
Patch needs improvement: |
set
|
Needs documentation: |
unset
|
Needs tests: |
unset
|
Patch needs improvement: |
unset
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
Good catch!
Regression in f333e3513e8bdf5ffeb6eeb63021c230082e6f95.