drop / create database之后Django无法syncdb

时间:2010-01-24 00:15:37

标签: django postgresql syncdb

我想重置数据库并发出一个drop数据库,后跟一个create database 在django应用程序通过psycopg2访问的postgresql服务器上。

当我执行./manage.py syncdb时出现以下错误:

(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

在postgresql日志中我收到以下错误:

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

我该如何解决这个问题?

5 个答案:

答案 0 :(得分:0)

尝试重置数据库,例如./manage.py重置your_app

答案 1 :(得分:0)

我遇到了同样的问题并将其追踪到django-mingus上2979ea3d4541f7b3c51c17e160bc95b468ac999b的提交

如果您重置为提交2f7eb8de7e2cb1c776e801a40f008048fcbb6d36,则同步应该正常。

答案 2 :(得分:0)

这是Django-Mingus使用的django-request中的一个问题。在syncdb期间,Django执行了一些db内省,并且相关的import引发了此异常。如果要从django-request或django-mingus中提取最新位,你就可以了。

答案 3 :(得分:0)

mySQL在遇到错误时不会使当前事务无效,其中postgres会抛出错误,并且在当前事务未中止之前不会运行其他查询。在这种情况下,您必须终止事务或使用该事务ID

进行提交

答案 4 :(得分:0)