Search code examples
djangopostgresqlsyncdb

Django can't syncdb after drop/create database


I wanted to reset a database and issued a drop database followed by a create database on a postgresql server accessed through psycopg2 by a django app.

When I do ./manage.py syncdb I get the following error:

(prod)root@ns204612:/home/someproject/prod/django-mingus/mingus# ./manage.py syncdb
Traceback (most recent call last):
  File "./manage.py", line 16, in <module>
    execute_manager(settings)
  File "/home/someproject/prod/lib/python2.6/site-packages/django/core/management/__init__.py", line 362, in execute_manager
    utility.execute()
  File "/home/someproject/prod/lib/python2.6/site-packages/django/core/management/__init__.py", line 303, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/someproject/prod/lib/python2.6/site-packages/django/core/management/base.py", line 195, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/someproject/prod/lib/python2.6/site-packages/django/core/management/base.py", line 222, in execute
    output = self.handle(*args, **options)
  File "/home/someproject/prod/lib/python2.6/site-packages/django/core/management/base.py", line 351, in handle
    return self.handle_noargs(**options)
  File "/home/someproject/prod/lib/python2.6/site-packages/django/core/management/commands/syncdb.py", line 52, in handle_noargs
    tables = connection.introspection.table_names()
  File "/home/someproject/prod/lib/python2.6/site-packages/django/db/backends/__init__.py", line 491, in table_names
    return self.get_table_list(cursor)
  File "/home/someproject/prod/lib/python2.6/site-packages/django/db/backends/postgresql/introspection.py", line 30, in get_table_list
    AND pg_catalog.pg_table_is_visible(c.oid)""")
  File "/home/someproject/prod/lib/python2.6/site-packages/django/db/backends/util.py", line 19, in execute
    return self.cursor.execute(sql, params)
psycopg2.InternalError: current transaction is aborted, commands ignored until end of transaction block

and in the postgresql log I got the following error:

2010-01-24 01:08:02 CET ERROR:  relation "django_site" does not exist
2010-01-24 01:08:02 CET STATEMENT:  SELECT "django_site"."id", "django_site"."domain", "django_site"."name" FROM "django_site" WHERE "django_site"."id" = 1  ORDER BY "django_site"."domain" ASC
2010-01-24 01:08:02 CET ERROR:  current transaction is aborted, commands ignored until end of transaction block
2010-01-24 01:08:02 CET STATEMENT:  
                    SELECT c.relname
                    FROM pg_catalog.pg_class c
                    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
                    WHERE c.relkind IN ('r', 'v', '')
                        AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
                        AND pg_catalog.pg_table_is_visible(c.oid)
2010-01-24 01:08:02 CET LOG:  could not receive data from client: Connection reset by peer
2010-01-24 01:08:02 CET LOG:  unexpected EOF on client connection

How can I fix that please ?


Solution

  • The cause of this was an issue in django-request which is used by Django-Mingus. During syncdb Django does some db introspection and a related import raised this exception. If you are to pull the latest bits from either django-request or django-mingus you'll be ok.