0

I'm trying to migrate all of the data in my SQLite database to a new MySQL database, to do so, I've been following the following steps (which I found in another question What's the best way to migrate a Django DB from SQLite to MySQL?). I've tried the following approaches:

  1. First I run a py manage.py dumpdata > datadump.json. Then, I change my settings.py file to use my new MySQL database. After that, I run a py manage.py migrate --run-syncdb And then I exclude contentType data by:
    python manage.py shell
    from django.contrib.contenttypes.models import ContentType
    ContentType.objects.all().delete()
    quit()
    
    And Lastly, I try to run a py manage.py loaddata datadump.json
  2. I've also tried to just run py manage.py dumpdata --exclude contenttypes --exclude auth.permission --exclude sessions --indent 2 > dump.json, followed by py manage.py loaddata dump.json.

The problem is that, in both approaches, in the very last step, when I'm trying to load the data into my new database, the following error is raised:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

I've been trying to investigate what could prevent or fix this error but nothing has come up. Any help is appreciated. Thanks in advance.

In case this is needed, this is how I setup my DB in my Django Project.

DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'naturalfitness_db',
            'USER': 'root',
            'PASSWORD': config('DB_PASSWORD'),
            'HOST': 'localhost', 
            'PORT': '3306',  
        }
    }

And my database already has all the tables needed to comply with all the models in my Django project.

Shadow
  • 33,525
  • 10
  • 51
  • 64
winston1420
  • 160
  • 9

1 Answers1

0

I was able to fix the problem by simply opening the JSON file in Notepad++ and changing the encoding to UTF-8 -_-

winston1420
  • 160
  • 9