开发者

Django can't syncdb after drop/create database

开发者 https://www.devze.com 2022-12-17 18:13 出处:网络
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.

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开发者_JAVA技巧 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 ?


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.


Try to reset you database like ./manage.py reset your_app


I was having the same issue and tracked it down to the commit at 2979ea3d4541f7b3c51c17e160bc95b468ac999b on django-mingus

If you reset back to commit 2f7eb8de7e2cb1c776e801a40f008048fcbb6d36, the sync should happen fine.


mySQL does not invalidate the current transaction when it encounters an error where postgres throws the error and do not run other query until the current transaction is not aborted. In this case you have to kill the transaction or commit with that transaction id


Look at here http://www.faqs.org/docs/ppbook/x15040.htm

0

精彩评论

暂无评论...
验证码 换一张
取 消