Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#1766 closed defect (fixed)

[patch] Syncdb fails if two models within an application refer to the same database table.

Reported by: clelland@… Owned by: adrian
Component: Core (Other) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


If two models within a single application, or in two applications within the same project, reference the same database table (by overriding db_table in the Meta class for at least one of them,) then ' syncdb' will try to create the table twice, causing the database backend to raise an exception, and will fail.

django/core/ is getting a list of existing tables through database introspection in order to avoid exactly this problem. Currently, however, it does not update that list as it creates tables, so if a table is mentioned twice, it will blindly try to create it twice.

This patch adds one line to syncdb() in to update the list of existing tables as they are created.

Attachments (1)

management.diff (482 bytes) - added by clelland@… 9 years ago.
One-line patch to resolve this issue

Download all attachments as: .zip

Change History (3)

Changed 9 years ago by clelland@…

One-line patch to resolve this issue

comment:1 Changed 9 years ago by adrian

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

(In [2835]) Fixed #1766 -- Fixed bug in syncdb where it allowed two models to have the same database table. Thanks, Ian Clelland

comment:2 Changed 9 years ago by Bryan Chow <fullfactor at gmail dot com>

Wow, that was fast! Thanks Adrian :)

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