#24632: PostgreSQL table inheritance
-------------------------------------+-------------------------------------
     Reporter:  yennicks             |                    Owner:
         Type:  New feature          |                   Status:  new
    Component:  contrib.postgres     |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:  orm postgresql       |             Triage Stage:  Accepted
  table-inheritance inheritance      |
  object-relational                  |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by charettes):

 I think it might be worth exploring a way to specify how model inheritance
 should be handled at the database level.

 This could allow us to support MTI (the actual), STI (Single Table
 Inheritance) and PostgreSQL table inheritance.

 IMHO it would be more worthwhile to abstract this whole concept with
 documented caveats and limitations because it's going to be hard to mimic
 the actual MTI implementation (Fk's as primary keys) with PostgreSQL table
 inheritance.

 For example, constraints are not inherited by children tables so the
 following scenario would fail if we simply replaced the existing MTI model
 on PostgreSQL by table inheritance.

 {{{#!python
 class Parent(models.Model):
     pass

 class Child(Parent):
     pass

 class Referent(models.Model):
     parent = models.ForeignKey(Parent)
 }}}

 {{{#!sql
 CREATE TABLE parent (id serial PRIMARY KEY);
 CREATE TABLE child () INHERITS (parent);
 CREATE TABLE referent (
     parent_id int REFERENCES parent
 );
 }}}

 {{{#!python
 >>> child = Child.objects.create()
 >>> ref = ParentReferent(parent=child)
 IntegrityError ...
 }}}

 {{{#!sql
 ERROR:  insert or update on table "referent" violates foreign key
 constraint "referent_parent_id_fkey"
 DETAIL:  Key (parent_id)=(1) is not present in table "parent".
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24632#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.de1b4ed0c914777da62e39e3859d51b6%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to