#26703: field automatically choosen as primary_key (primary_key=False do not 
work)
-------------------------------------+-------------------------------------
     Reporter:  nbremond             |      Owner:  nobody
         Type:  Bug                  |     Status:  new
    Component:  Database layer       |    Version:  1.9
  (models, ORM)                      |   Keywords:  multi-table
     Severity:  Normal               |  inheritance, primary_key,
                                     |  OneToOneField
 Triage Stage:  Unreviewed           |  Has patch:  0
Easy pickings:  0                    |      UI/UX:  0
-------------------------------------+-------------------------------------
 I tried to use multi-table inheritance with a OneToOne field to the parent
 class in the child class but this field seems to be detected as
 primary_key by Django (there is only one row in the database).

 The field has the same type as the parent link automatically created by
 Django and
 the [https://docs.djangoproject.com/en/1.10/topics/db/models/#specifying-
 the-parent-link-field doc on inheritance] tells that we can choose to use
 a such field for the inheritance relation with `parent_link=True` but I
 need the inheritance relation AND my other relation.
 I tried to add `parent_link=False` but this don't change anything.
 If I add `null=True` I got an error :
 {{{
 SystemCheckError: System check identified some issues:

 ERRORS:
 testapp.A.other: (fields.E007) Primary keys must not have null=True.
         HINT: Set null=False on the field, or remove primary_key=True
 argument.
 from django.db import models
 }}}
 So I tried to add `primary_key=False` but that don't change anything.

 There is a minimal code wich reproduce the error

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

 class A(Base):
     other=models.OneToOneField(Base,
             parent_link=False,#do not change anything
             primary_key=False,#do not change anything
             null=True,#raise a SystemCheckError
             related_name='other_base',
             )

 }}}

 I can continue my project if I replace the `OneToOneField` by a
 `ForeignKey` with `unique=True` but I have a warning with a hint to
 replace the `ForeignKey` by a `OneToOneField` :
 {{{
 System check identified some issues:

 WARNINGS:
 testapp.A.other: (fields.W342) Setting unique=True on a ForeignKey has the
 same effect as using a OneToOneField.
         HINT: ForeignKey(unique=True) is usually better served by a
 OneToOneField.
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26703>
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/051.63a3a3b1ae1c158f4f6431875548a3c6%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to