gpt4 book ai didi

python - Wagtail 将 sqlite 移动到 postgres 数据库

转载 作者:太空狗 更新时间:2023-10-30 01:36:30 24 4
gpt4 key购买 nike

问题

我有一个空的(已迁移的)postgres 数据库,我想将数据从我的 sqlite 数据库移动到该数据库中。

我尝试过的

  • 我用

    导出
    ./manage.py dumpdata --exclude auth.permission --exclude contenttypes --natural-foreign

    然后使用 ./manage.py loaddata 将数据加载到 postgres 数据库中。

    这里的问题是 wagtail 需要内容类型,我得到一个运行时错误

    FooPage matching query does not exist. 

    /wagtail/wagtailcore/models.py:639 
    return content_type.get_object_for_this_type(id=self.id)
  • 不要使用 dumpdata 排除 contenttypes。现在 loaddata 命令失败并出现 IntegrityError:Key ... already exists

  • 我试图在加载数据之前删除所有 ContentType 模型对象,这样它就不会提示重复的键。虽然这在使用 sqlite 数据库时有效,但它在 postgres 数据库上失败并出现 IntegrityError

    Key (id)=(1) is still referenced from table "wagtailcore_page".

使用过的版本

  • django 1.11.9
  • 鹡鸰1.12.3
  • python 3.5

相关

Problems with contenttypes when loading a fixture in Django

最佳答案

pgloader您可以执行命令指令将数据从 SQLite 加载到 Postgres。

使用 Homebrew 在 OSX 上安装:

brew install pgloader

创建一个脚本文件。例如 migrate.script:

load database
from sqlite:///path/to/db.sqlite3
into postgresql:///yourpostgresdbname

with include drop, create tables, create indexes, reset sequences

set work_mem to '16MB', maintenance_work_mem to '512 MB';

运行它:

pgloader migrate.script

我使用包含最小 Wagtail 项目(一些页面、修订和图像)的 SQLite 数据库进行了测试,它运行良好。

关于python - Wagtail 将 sqlite 移动到 postgres 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48141975/

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