Is it actually possible to define a primary key that is a
concatenation of two fields?

I'm working on a project to get the admin to work on top of a legacy
db - it's an old db with a few, ahem, design problems.  For the most
part I've been able to get around the bad structure with a few simple
model adjustments, but today I came across a table that has just three
cols - and no id:


class Priority(models.Model):
    tags = models.ForeignKey(Tags)
    content = models.ForeignKey(Content)
    rank = models.IntegerField()

    class Meta:
        db_table = u'priority'
        unique_together = (("tags", "content"),)


My preference would be just to add an 'id' column to the table, but
we're trying to keep db changes to a minimum (changing one means
changing the same table in at least a dozen more - not optimal, but it
is what it is).  Without it, I'm throwing "Unknown column
'priority.id' in 'field list'" as an error.

Each record needs to be unique on tags + content anyway.  Would it be
possible to define a concatenated primary key using these two cols?
What approach would you take?  (Or should I just fight a little harder
to make the adjustment to the table itself?)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to