最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Wagtail and dumpdata and loaddata - Stack Overflow

programmeradmin2浏览0评论

I am looking for working examples of using dumpdata and loaddata with Wagtail 6.4. I'm having trouble getting it to work correctly.

Here's my setup process:

My setup:

mkdir wagtail-example
wagtail start wexample wagtail-example/
cd wagtail-example/
uv init && rm hello.py
nvim requirements.txt      # Update wagtail version from 6.3 to 6.4
uv add -r requirements.txt
rm requirements.txt        # Remove duplicit dependency definition, prefer pyproject.toml
uv run manage.py migrate
uv run manage.py createsuperuser
uv tree --depth 1
Resolved 33 packages in 0.65ms
wagtail-example v0.1.0
├── django v5.1.6
└── wagtail v6.4.1

I am using the default SQLite database. Everything seems to be running fine.

Next, I tried to export data using dumpdata:

uv run manage.py dumpdata > data.json

I also tried the alternative command suggested on yellowduck.be:

uv run manage.py dumpdata --natural-foreign --indent 2 \
                        -e contenttypes -e auth.permission \
                        -e wagtailcore.groupcollectionpermission \
                        -e wagtailcore.grouppagepermission -e wagtailimages.rendition \
                        -e sessions > data.json

After exporting, I attempted to import the data:

rm db.sqlite3 # delete old db
uv run manage.py migrate --run-syncdb
uv run manage.py loaddata data.json

However, every time I run loaddata, I encounter the following error:

django.db.utils.IntegrityError: Problem installing fixture '~/src/wagtail-example/data.json': Could not load wagtailsearch.IndexEntry(pk=1): constraint failed

I understand this is likely because migrate --run-syncdb creates a root page and a home page, which use the first two primary keys. Even if I delete these pages, the primary keys seem to be reserved.

Is there a reliable method to use dumpdata and loaddata in current versions of Wagtail?

发布评论

评论列表(0)

  1. 暂无评论