I'm mapping an existing database structure into Django models. I have a many-to-many structure where the association table is natural-keyed:
CREATE TABLE foo (id INTEGER PRIMARY KEY);
CREATE TABLE bar (id INTEGER PRIMARY KEY);
CREATE TABLE foo2bar (foo_id INTEGER REFERENCES foo(id),
bar_id INTEGER REFERENCES bar(id),
PRIMARY KEY (foo_id, bar_id)
);
Is there no way to get Django's ORM to map this? Must I change foo2bar to use a surrogate key? E.g.
CREATE TABLE foo2bar (id INTEGER PRIMARY KEY,
foo_id INTEGER REFERENCES foo(id),
bar_id INTEGER REFERENCES bar(id)
);
CREATE UNIQUE INDEX ix_foo2bar_uniq ON foo2bar (foo_id, bar_id);