Pri*_*han 4 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' 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.
Run Code Online (Sandbox Code Playgroud)
这是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;
Run Code Online (Sandbox Code Playgroud)
我有一个包含多个模型的数据库,并且它们之间有许多外键关系.从我通过互联网阅读的内容来看,我理解Truncate应该用来删除依赖的表.我无法确定在dbshell中使用它的确切语法.
我还以sudo用户身份访问postgresql shell,并尝试使用删除数据库
DROP DATABASE DBNAME
Run Code Online (Sandbox Code Playgroud)
命令.但数据库仍然存在.
编辑:
感谢stevejalim的评论,我能够删除数据库并创建一个新数据库.我再次运行syncdb命令并再次创建数据库.但是尝试使用loaddata命令加载数据库会引发错误
IntegrityError: duplicate key value violates unique constraint
Run Code Online (Sandbox Code Playgroud)
任何有关这方面的帮助将非常感激.
您无法删除数据库的原因可能是您已连接到它.我必须猜测,因为你正在阻止实际的错误消息.改为连接到默认维护数据库postgres(作为db的超级用户或所有者):
psql postgres
Run Code Online (Sandbox Code Playgroud)
并从那里启动命令:
DROP DATABASE dbname;
Run Code Online (Sandbox Code Playgroud)
查看这个相关的问题od dba.SE,以获得一个强大的方法来删除一个不想去的数据库.
关于您得到的新错误:您在其中一个表上定义了UNIQUE或PRIMARY索引或约束,但尝试插入重复值.在PostgreSQL的现代版本中,您可以在错误消息中获得更多信息.喜欢:
ERROR: duplicate key value violates unique constraint "tbl_pkey"
DETAIL: Key (tbl_id)=(10) already exists.
Run Code Online (Sandbox Code Playgroud)
提出一个问题:你使用哪个版本的PostgreSQL?
在任何情况下:检查数据库日志文件以获取这些详细信息并修复源中的重复值(或删除UNIQUE约束).
| 归档时间: |
|
| 查看次数: |
6370 次 |
| 最近记录: |