Opened 10 years ago

Closed 9 years ago

#3484 closed (duplicate)

Poor error message (or functionality) when using unsaved models as foreign keys

Reported by: Dave Abrahams <dave@…> Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

This reduced case untested, sorry.

from django.db import models

class X(models.Model):
    pass

class Y(models.Model):
    x = models.ForeignKey(X)

x = X()
Y(x=x).save()

The result,
IntegrityError: ERROR: null value in column "presenter_id" violates not-null constraint, is cryptic at best. Maybe rather than improving the error message, it should recursively save all unsaved models?

Change History (4)

comment:1 Changed 10 years ago by Dave Abrahams <dave@…>

Oops, not presenter_id, but x_id

comment:2 Changed 10 years ago by Chris Beaven

Triage Stage: UnreviewedDesign decision needed

I think just improving the error message would be enough. But what does core think?

comment:3 Changed 10 years ago by Chris Beaven

Summary: Poor error message (or functionality)Poor error message (or functionality) when using unsaved models as foreign keys

comment:4 Changed 9 years ago by James Bennett

Resolution: duplicate
Status: newclosed

Duplicate of #3016, I believe; fixing that should fix this.

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