gpt4 book ai didi

删除/创建数据库后 Django 无法同步数据库

转载 作者:行者123 更新时间:2023-11-29 11:37:34 25 4
gpt4 key购买 nike

我想重置数据库并发出一个删除数据库,然后是一个创建数据库在 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

请问我该如何解决?

最佳答案

这是由 Django-Mingus 使用的 django-request 中的一个问题引起的。在 syncdb 期间,Django 会进行一些数据库自省(introspection),并且相关的导入会引发此异常。如果你要从 django-request 或 django-mingus 中获取最新的位,你会没事的。

关于删除/创建数据库后 Django 无法同步数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2125326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com