Skip to content
Home » Solving “CommandError: Unable to serialize database: ‘charmap’ codec can’t encode character…”

Solving “CommandError: Unable to serialize database: ‘charmap’ codec can’t encode character…”

I’ve been working in Django a lot lately and needed to dump my database using Django’s dumpdata command. However, that produced an error. Here’s how I solved it.

django-admin dumpdata <app>.<object> -o db_dump_<suffix>.json

However, halfway the dump, my terminal returned an error.

CommandError: Unable to serialize database: 'charmap' codec can't encode character '\ufeff' in position 110: character maps to <undefined>

Apparently, there was a Byte Order Mark or BOM somewhere in my SQLite database, which uses UTF-8 encoding by default. 😒 However, Python, in the terminal, cannot process it, since it uses Unicode by default.

The solution? Force Python to use UTF-8, as follows:

python -Xutf8 manage.py dumpdata <app>.<object> -o db_dump_<suffix>.json

Now, your dump will be properly processed and stored as a JSON file.

10 thoughts on “Solving “CommandError: Unable to serialize database: ‘charmap’ codec can’t encode character…””

  1. Informative article very good approach towards data you provides good work. May all your dreams come true and may you find happiness and success in all your endeavors. Best wishes to you always.

Leave a Reply

Your email address will not be published. Required fields are marked *