Legacy read-only DB with no primary key
Closed this issue · 5 comments
I'm using Django to interface with a read-only legacy database (in addition to a primary database).
One of the legacy tables has been created haphazardly without a primary key column, and is essentially a M2M table. The auto-generated model looks like so:
class LegacyTable(models.Model):
a = models.ForeignKey(A, db_column='a')
b = models.ForeignKey(B, db_column='b')
class Meta:
managed = False
db_table = 'legacy_table'
Obviously, running queries on this model throws the usual errors since there's no id
column and no primary_key
defined. I tried adding the following composite key field, thinking it might make Django happy:
id = db.MultiFieldPK('a', 'b')
but when trying to run a simple query, I get:
File "/home/user/.virtualenvs/proj/lib/python2.7/site-packages/compositekey/db/models/sql/compiler.py", line 90, in _setup_joins
opts, alias, False)
ValueError: need more than 5 values to unpack
Is this an error on my part, or is this scenario not supported at all? I'm running Django 1.6 if it matters.
Hi,
You got it, the problem is compositekey is been written for django 1.4 and now support django 1.5.5.
Support for Django 1.6 is still working in progress. There is an issue opened.
Cool, thanks. Meanwhile I created a workaround at the database level, but would be happy to see this resolved for latest and greatest Django.
How did you solve this problem
@profmcdan I really can't remember, sorry.