django-admin creates invalid m2m table if the related models have same primary key name
|Reported by:||Russell Keith-Magee||Owned by:||Russell Keith-Magee|
|Component:||Core (Management commands)||Version:||magic-removal|
|Severity:||normal||Keywords:||recursive m2m primary key|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Consider the following model
class Article(models.Model): ... related = models.ManyToManyField("Article")
This model currently breaks magic-removal - the SQL created on install is invalid, because the m2m table for the many-to-many field has two columns named article_id. This is easy to cause if you recursively define a m2m relationship; you can probably get a similar problem if you use custom primary key names.
At the very least, this should be picked up as a validation error; ideally, we need a strategy for producing unique column names in the m2m table.