Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法刷新Django中的Postgres DB_Django_Postgresql_Dump - Fatal编程技术网

无法刷新Django中的Postgres DB

无法刷新Django中的Postgres DB,django,postgresql,dump,Django,Postgresql,Dump,我正在尝试使用loaddata命令加载本地postgres数据库,其中包含json转储的数据(来自在线数据库)。但由于“完整性错误”而失败,因为我已经在数据库中使用主键保存了一些数据。然后我尝试刷新数据库,以便在syncdb之后将其恢复到状态。但它给了我以下信息,但失败了 You have requested a flush of the database. This will IRREVERSIBLY DESTROY all data currently in the 'app' databa

我正在尝试使用loaddata命令加载本地postgres数据库,其中包含json转储的数据(来自在线数据库)。但由于“完整性错误”而失败,因为我已经在数据库中使用主键保存了一些数据。然后我尝试刷新数据库,以便在syncdb之后将其恢复到状态。但它给了我以下信息,但失败了

You have requested a flush of the database.
This will IRREVERSIBLY DESTROY all data currently in the 'app' database,
and return each table to the state it was in after syncdb.
Are you sure you want to do this?

    Type 'yes' to continue, or 'no' to cancel: yes
Error: Database app couldn't be flushed. Possible reasons:
  * The database isn't running or isn't configured correctly.
  * At least one of the expected database tables doesn't exist.
  * The SQL was invalid.
Hint: Look at the output of 'django-admin.py sqlflush'. That's the SQL this command wasn't able to run.
The full error: cannot truncate a table referenced in a foreign key constraint
DETAIL:  Table "taskapp_taskrequest" references "taskapp_task".
HINT:  Truncate table "taskapp_taskrequest" at the same time, or use TRUNCATE ... CASCADE.
这是sqlflush命令的相应输出

BEGIN;
TRUNCATE "auth_permission", "auth_group", "tagging_taggeditem", "auth_user_user_permissions", "taskapp_task_reviewers", "taskapp_task", "django_site", "profile_profile", "django_content_type", "profile_notification", "django_session", "auth_user_groups", "taskapp_pyntrequest", "profile_rolerequest", "tagging_tag", "taskapp_textbook_chapters", "registration_registrationprofile", "taskapp_textbook", "django_admin_log", "auth_group_permissions", "taskapp_task_selected_users", "taskapp_taskcomment", "south_migrationhistory", "taskapp_task_claimed_users", "taskapp_taskclaim", "taskapp_workreport", "auth_message", "taskapp_reportcomment", "auth_user";
SELECT setval(pg_get_serial_sequence('"registration_registrationprofile"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"tagging_tag"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"tagging_taggeditem"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"south_migrationhistory"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"auth_permission"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"auth_group"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"auth_user"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"auth_message"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"django_content_type"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"django_site"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"django_admin_log"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"profile_profile"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"profile_notification"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"profile_rolerequest"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"taskapp_task"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"taskapp_taskcomment"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"taskapp_taskclaim"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"taskapp_workreport"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"taskapp_reportcomment"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"taskapp_pyntrequest"','id'), 1, false);
SELECT setval(pg_get_serial_sequence('"taskapp_textbook"','id'), 1, false);
COMMIT;
我有一个数据库,其中有多个模型和许多外键关系。从我在互联网上读到的内容,我理解Truncate应该用于删除依赖于的表。我不太清楚在dbshell中使用它的确切语法

我还访问了postgresqlshell,并尝试使用

DROP DATABASE DBNAME
指挥部。但数据库仍然存在

编辑:

多亏了stevejalim的评论,我才能够删除数据库并创建了一个新的数据库。我再次运行syncdb命令并再次创建了数据库。但是尝试使用loaddata命令加载数据库会抛出错误

IntegrityError: duplicate key value violates unique constraint

在此方面的任何帮助都将不胜感激。

您可以尝试使用postgres命令行工具删除数据库

dropdb dbname

无法删除数据库的原因可能是您已连接到该数据库。我不得不猜测,因为你隐瞒了实际的错误消息。改为连接到默认维护数据库
postgres
(作为数据库的超级用户或所有者):

然后从那里启动命令:

DROP DATABASE dbname;
请查看这篇文章,了解删除不想删除的数据库的可靠方法


关于您得到的新错误:您在一个表上定义了唯一的或主要的索引或约束,但尝试插入重复的值。在现代版本的PostgreSQL中,您可以在错误消息中获得更多信息。比如:

ERROR:  duplicate key value violates unique constraint "tbl_pkey"
DETAIL:  Key (tbl_id)=(10) already exists.
提出了一个问题:您使用哪个版本的PostgreSQL?

在任何情况下:检查数据库日志文件以了解这些详细信息,并修复源中的重复值(或删除唯一约束)。

听起来很傻,但在DB drop命令之后是否有分号<代码>删除数据库DBNAME我的错。我一直以为我走错了方向。
truncate
不会删除任何表。它只删除所有行。
ERROR:  duplicate key value violates unique constraint "tbl_pkey"
DETAIL:  Key (tbl_id)=(10) already exists.