Opened 6 years ago

Closed 6 years ago

Last modified 4 years ago

#12559 closed (duplicate)

Wrong SQL in M2M fields

Reported by: anonymous Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2-alpha
Severity: Keywords:
Cc: andrey.offline@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by Alex)

I have some strange problem after updating to the 1.2 alpha version.

My simplified model is

class Sticker(models.model):
    telephones = models.ManyToManyField("account.Telephone")

when i run

sticker = Sticker.object.get(pk=1)
sticker.telephones.all()

Django generated sql is:

u'SELECT `account_telephone`.`id`, `account_telephone`.`tel_city`, `account_telephone`.`tel_number`, `account_telephone`.`profile_id` FROM `account_telephone` INNER JOIN `service_sticker_telephones` ON (`account_telephone`.`id` = `service_sticker_telephones`.`account.telephone_id`) WHERE `service_sticker_telephones`.`sticker_id` = 1'

The wrong thing is service_sticker_telephones.account.telephone_id , it should be service_sticker_telephones.telephone_id, but somehow the application name was added. Even more interesting is that in my model i have another M2M field that works well.

I tried to debug, but ORM layer is to complex for me. By the way, my backend is MySQL.

Change History (3)

comment:1 Changed 6 years ago by Alex

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Fixed formatting, please use preview.

comment:2 Changed 6 years ago by russellm

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

I'm fairly certain this is a duplicate of #12386, which I just fixed in [12226]. Please reopen if I am mistaken.

comment:3 Changed 4 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

Note: See TracTickets for help on using tickets.
Back to Top