Search code examples
pythondjango

Import Error while using python manage.py migrate command


Recently, I forked some source code from github to use as a basis for a project that I'm using to learn Django. As per the deployment instructions, I tried to use this command for the database in my terminal:

python manage.py migrate

Yet I keep getting this error:

ImportError: cannot import name 'force_text' from 'django.utils.encoding' (C:\Users\afric.virtualenvs\Online-Examination-System-aZtpAN9a\lib\site-packages\django\utils\encoding.py)

The error stems from the terminal trying to process this command:

from django.utils.encoding import force_bytes, force_text, DjangoUnicodeDecodeError

Can anyone please help me solve this?


Solution

  • It seems that the project you forked was written in the older version of Django, since force_text has changed to force_str since Django 3.0. So updating or reinstalling Django might just be the easiest way to resolve the issue you're facing. In addition, you can try to find the root file which causes the problem and replace the import.