class KevinExample(models.Model):
code = models.CharField(db_column='Code', primary_key=True, max_length=50) # Field name made lowercase.
lineid = models.IntegerField(db_column='LineId') # Field name made lowercase.
object = models.CharField(db_column='Object', max_length=20, blank=True, null=True) # Field name made lowercase.
loginst = models.IntegerField(db_column='LogInst', blank=True, null=True) # Field name made lowercase.
u_contrattr = models.ForeignKey('KevinExpAttr', models.DO_NOTHING, db_column='U_contrattr', max_length=50, blank=True, null=True) # Field name made lowercase.
u_attrlinedata = models.CharField(db_column='U_attrlinedata', max_length=50) # Field name made lowercase.
class Meta:
managed = False
db_table = '@KEVIN_EXAMPLE'
unique_together = (('code', 'lineid'),)
I did some Google searches for you.
There’s still an open ticket for it, open for the past 12 years:
https://code.djangoproject.com/ticket/373
There’s plenty of people asking the same question. Here’s one on Stack Overflow:
And it looks like there’s an app for it that hasn’t been updated since 2014:
https://github.com/simone/django-compositekey
In short, though, it looks like you’re doing everything correctly. You could always overwrite the save method and the refresh_from_db method for your use case.
If you can change the table at all, I would add an ID column and skip specifying the primary_key column in the model. You could also make a new view inside the database that is an interface to the foreign table and write your trigger SQL in your database system to handle inserts, updates, and deletes.
--
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...@googlegroups.com.
To post to this group, send email to
django...@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/857e15d5-e46b-4f1e-b1f3-e5c24b1f3bd8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.