Code

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#1346 closed defect (fixed)

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

Reported by: russellm Owned by: russellm
Component: Core (Management commands) Version: magic-removal
Severity: normal Keywords: recursive m2m primary key
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 (0)

Change History (5)

comment:1 Changed 8 years ago by russellm

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

comment:2 Changed 8 years ago 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.

comment:3 Changed 8 years ago by russellm

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

comment:4 Changed 8 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(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.

comment:5 Changed 8 years ago by russellm

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.