[Answered ]-Can I avoid redundant primary key columns in a MySQL table for django (python)?

2👍

You could create a compound primary key on your through table (with ALTER TABLE). You could also drop the id column from the table. None of this would harm django in way since the way ManyToMany fields work in the backend they wouldn’t use the id column anyway.

However you should note that getting compound PK to work in django is basically a non starter. This shouldn’t be an issue for you as no table should have a ForeignKey to your through table (for any reason that I can think of at least.

So in summary. Compound primary keys don’t work with django. So if you ever need to have a ForeignKey to a table with a compound PK you are basically SOL. Finally there is no real pro about using a compound PK here, but no real con either (in this one and only case). So why are you spending your time worrying about this?

👤John

Leave a comment