Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#30813 closed Bug (invalid)

dumpdata > flush > loaddata.

Reported by: Maksych Owned by: nobody
Component: Core (Management commands) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

After commands:

python manage.py dumpdata > db.json
python manage.py loaddata db.json

All it`s okay, but after:

python manage.py flush
python manage.py loaddata db.json

Have exception:

django.db.utils.IntegrityError: Problem installing fixture 'D:\projects\python\django\ultrashop_backend\db.json': Could not load contenttypes.ContentType

Attachments (1)

photo_2019-09-27_18-12-35.jpg (67.2 KB ) - added by Maksych 5 years ago.

Download all attachments as: .zip

Change History (4)

by Maksych, 5 years ago

comment:1 by Mariusz Felisiak, 5 years ago

Resolution: invalid
Status: newclosed
Summary: dumpdata > flush > loaddatadumpdata > flush > loaddata.
Version: 2.2master

dumpdata dumps primary keys by default which don't exist anymore after flush, so it's expected that such combination of commands fails. You should try:

django-admin dumpdata  --natural-foreign --natural-primary 

to avoid dumping auto primary keys (see documentation).

Closing per TicketClosingReasons/UseSupportChannels.

Version 0, edited 5 years ago by Mariusz Felisiak (next)

comment:2 by Maksych, 5 years ago

No, I tell about:

python manage.py flush

My full actions:

django-admin startproject project .
python manage.py makemigrations
python manage.py migrate
python manage.py dumpdata > db.json
python manage.py loaddata db.json

And all it's okay, but after:

python manage.py flush
python manage.py loaddata db.json

Raised exception because content-types after flush is diferent betwen after migrate.

comment:3 by Mariusz Felisiak, 5 years ago

This is documented behavior, please take a look at flush documentation:

Removes all data from the database and re-executes any post-synchronization handlers. The table of which migrations have been applied is not cleared. If you would rather start from an empty database and re-run all migrations, you should drop and recreate the database and then run migrate instead.

so flush removes all data from the database and re-executes post-synchronization handlers which recreates ContentType's with different IDs.

Note: See TracTickets for help on using tickets.
Back to Top