Opened 17 years ago

Closed 17 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: dev
Severity: Keywords:
Cc: tailofthesun@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi,

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 manage.py syncdb             
Creating table auth_message
Traceback (most recent call last):
  File "manage.py", line 11, in ?
    execute_manager(settings)
  File "/usr/lib/python2.4/site-packages/django/core/management.py", line 1736, in execute_manager
    execute_from_command_line(action_mapping, argv)
  File "/usr/lib/python2.4/site-packages/django/core/management.py", line 1633, in execute_from_command_line
    action_mapping[action](int(options.verbosity), options.interactive)
  File "/usr/lib/python2.4/site-packages/django/core/management.py", line 572, in syncdb
    cursor.execute(statement)
  File "/usr/lib/python2.4/site-packages/django/db/backends/util.py", 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@… 17 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 by tailofthesun@…, 17 years ago

Cc: tailofthesun@… added

I've tracked the bug to core/management.py:543 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.

by tailofthesun@…, 17 years ago

comment:2 by tailofthesun@…, 17 years ago

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 by Malcolm Tredinnick, 17 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Malcolm Tredinnick, 17 years ago

Nice debugging and the fix looks correct. Thanks.

comment:5 by Malcolm Tredinnick, 17 years ago

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