Opened 5 years ago

Last modified 5 years ago

#30537 closed Bug

ORM: ForeignKey: inconsistent handling of referenced obj. id — at Initial Version

Reported by: Aliaksei Owned by: nobody
Component: Database layer (models, ORM) Version: 2.0
Severity: Normal Keywords: ORM, ForeignKey, NOT NULL constraint, inconsistency
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In short: if referenced obj. is saved after attaching to a referencing obj. its id field (i.e. <refrerenced_obj>_id) there remains None.

In details:

class ReferencedObj(Model):
    ...

class ReferencingObj(Model):

    referenced_obj = ForeignKey(ReferencedObj)
    ...

x = ReferencedObj()
y = ReferencingObj()

y.referenced_obj = x

x.save()

y.save() -----→ NOT NULL constraint failed: ..._referencingobj.referenced_obj_id

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top