code.dev.world
code.dev.world

Reputation: 221

Django dumpdata generates invalid json format file

I'm working Django1.11. and I want to move from sqlite to PostgreSQL. So I need to dump data from Sqlite and load to PostgreSQL. I generate the dumped data with

python3 manage.py dumpdata > db.json

I have changed db setting to PostgreSQL and did

python3 manage.py loaddata db.json

and got this error.

raise JSONDecodeError("Expecting value", s, err.value) from None

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

So I use hexdump and tried.

raise JSONDecodeError("Expecting value", s, err.value) from None

django.core.serializers.base.DeserializationError: Problem installing fixture '/var/lib/myproject/fixtures/db.json': Expecting value: line 1 column 1 (char 0)

I took the look at db.json and it is not valid json.

Upvotes: 3

Views: 1272

Answers (1)

code.dev.world
code.dev.world

Reputation: 221

I'm working on linux.The problem was that at the head of the db.json,the sentence "trying windows paths instead" is attached and highlighted. When I open the file using vi command, I thought it's not part of the file. But it is the part of the file. I just manually deleted this sentence. It worked. But finally I didn't use python loaddata for database migration. You may have many errors if you use pyhton functions. So I quitted do it on the Django built-in function and used pgloader. It's easy way with no errors.

Upvotes: 3

Related Questions