Opened 11 years ago

Closed 11 years ago

#4678 closed (fixed)

second and subsequent runs of syncdb fails with "table already exists"

Reported by: dmitry@… Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: tailofthesun@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:



I'm using postgresql and psycopg2. I'm new to django so I just tried to follow the steps described in the tutorial. When I ran syncdb for the second time (after creating the model) I got the following:

$ python syncdb             
Creating table auth_message
Traceback (most recent call last):
  File "", line 11, in ?
  File "/usr/lib/python2.4/site-packages/django/core/", line 1736, in execute_manager
    execute_from_command_line(action_mapping, argv)
  File "/usr/lib/python2.4/site-packages/django/core/", line 1633, in execute_from_command_line
    action_mapping[action](int(options.verbosity), options.interactive)
  File "/usr/lib/python2.4/site-packages/django/core/", line 572, in syncdb
  File "/usr/lib/python2.4/site-packages/django/db/backends/", line 18, in execute
    return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "auth_message" already exists

Attachments (1)

postgresql_psycopg2-base.diff (492 bytes) - added by tailofthesun@… 11 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 11 years ago by tailofthesun@…

Cc: tailofthesun@… added

I've tracked the bug to core/ in revision [5519]. The table_list is returned as a sequence of lower-case strings. Since PostgreSQL uses case insensitive names, the name of each table compared to table_list is uppercased, and thus the comparison on line 560 always evaluates to False. I'm not sure how the other backends work, but at least for postgresql_psycopg2, the names should not be uppercased.

Changed 11 years ago by tailofthesun@…

comment:2 Changed 11 years ago by tailofthesun@…

Has patch: set

Actually, PostgreSQL does use case sensitive table names. I also noticed the postgresql backend sets uses_case_insensitive_names to False, so I've attached a patch for the postgresql_psycopg2 backend.

comment:3 Changed 11 years ago by Malcolm Tredinnick

Triage Stage: UnreviewedAccepted

comment:4 Changed 11 years ago by Malcolm Tredinnick

Nice debugging and the fix looks correct. Thanks.

comment:5 Changed 11 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [5528]) Fixed #4678 -- Fixed table name matching during syncdb for pyscopg2 backend
(the psycopg backend was already correct). Patch from tailofthesun@….

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