Friday, April 21, 2017

Re: First models.py needs tuning

On Tue, Apr 18, 2017 at 03:13:24PM -0700, Rich Shepard wrote:
> Converting from the postgres schema to a Django models.py for my first
> Django project. Most of the syntax (64 lines in the file) should be correct,
> but there are two conditions that I have not found how to handle.
>
> First, a couple of classes have primary keys with three fields. I know
> there's a models.PrimaryKey but haven't found an example of how to apply
> that to a field that foreign key fields.

I have bad news for you – Django does not at this point in time have
support for multi-column primary keys. A large part of the ORM is
built around the assumption that each model instance is identified by
a single field acting as its primary key.

A lot of time and effort has been spent trying to implement them, but
it's a huge project, and it's not even close to being ready to get
merged. As far as I know, nobody is currently even actively working on
this feature. If you're interested, look up composite fields in the
archives of django-developers@.

For the foreseeable future, though, I'd strongly recommend that you
save yourself a lot of trouble, and just add a surrogate primary key
field to all your tables and models.

Cheers,

Michal

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20170421085007.GV23772%40koniiiik.org.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment