Django

Code

Ticket #1346 (closed: fixed)

Opened 3 years ago

Last modified 2 years ago

django-admin creates invalid m2m table if the related models have same primary key name

Reported by: russellm Assigned to: russellm
Milestone: Component: django-admin.py
Version: magic-removal Keywords: recursive m2m primary key
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

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.

Attachments

Change History

02/24/06 04:15:31 changed by russellm

(In [2380]) magic-removal: Refs #1346 -- Added unit tests for expected behaviour of self referential m2m fields.

02/24/06 04:25:06 changed by russellm

(In [2381]) magic-removal: Refs #1346 -- Refactored query logic for m2m descriptor fields, and added logic to m2m name methods to allow m2m_recursive tests to create a valid SQL table.

02/24/06 04:28:49 changed by russellm

(In [2382]) magic-removal: Refs #1346 -- Added the production of 'mirror' entries in the m2m table for m2m relations to self.

02/24/06 04:36:09 changed by russellm

  • status changed from new to closed.
  • resolution set to fixed.

(In [2383]) magic-removal: Fixes #1346 -- Added ability for m2m relations to self to be optionally non-symmetrical. Added unit tests for non-symmetrical behaviour.

02/24/06 04:42:34 changed by russellm

(In [2384]) magic-removal: Refs #1346 -- Removed some redundant code that was missed in the checkin for r2381.


Add/Change #1346 (django-admin creates invalid m2m table if the related models have same primary key name)




Change Properties
Action