I just converted my SQLITE database to a MySQL database. It appears that I converted it correctly. My application no longer works, though. The traceback is:
Error running WSGI application 2023-04-08 06:55:06,159: django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. 2023-04-08 06:55:06,159: Did you install mysqlclient? 2023-04-08 06:55:06,159: File "/var/www/waynemelnick_pythonanywhere_com_wsgi.py", line 17, in 2023-04-08 06:55:06,159: application = get_wsgi_application() 2023-04-08 06:55:06,159: 2023-04-08 06:55:06,160: File "/home/WayneMelnick/.virtualenvs/mysite-virtualenv/lib/python3.10/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application 2023-04-08 06:55:06,160: django.setup(set_prefix=False) 2023-04-08 06:55:06,160: 2023-04-08 06:55:06,160: File "/home/WayneMelnick/.virtualenvs/mysite-virtualenv/lib/python3.10/site-packages/django/init.py", line 24, in setup 2023-04-08 06:55:06,160: apps.populate(settings.INSTALLED_APPS) 2023-04-08 06:55:06,160: 2023-04-08 06:55:06,160: File "/home/WayneMelnick/.virtualenvs/mysite-virtualenv/lib/python3.10/site-packages/django/apps/registry.py", line 116, in populate 2023-04-08 06:55:06,161: app_config.import_models() 2023-04-08 06:55:06,161: 2023-04-08 06:55:06,161: File "/home/WayneMelnick/.virtualenvs/mysite-virtualenv/lib/python3.10/site-packages/django/apps/config.py", line 269, in import_models 2023-04-08 06:55:06,162: self.models_module = import_module(models_module_name) 2023-04-08 06:55:06,162: 2023-04-08 06:55:06,162: File "/home/WayneMelnick/.virtualenvs/mysite-virtualenv/lib/python3.10/site-packages/django/contrib/auth/models.py", line 3, in 2023-04-08 06:55:06,162: from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager 2023-04-08 06:55:06,162: 2023-04-08 06:55:06,163: File "/home/WayneMelnick/.virtualenvs/mysite-virtualenv/lib/python3.10/site-packages/django/contrib/auth/base_user.py", line 49, in 2023-04-08 06:55:06,163: class AbstractBaseUser(models.Model): 2023-04-08 06:55:06,163: 2023-04-08 06:55:06,163: File "/home/WayneMelnick/.virtualenvs/mysite-virtualenv/lib/python3.10/site-packages/django/db/models/base.py", line 141, in new 2023-04-08 06:55:06,163: new_class.add_to_class("_meta", Options(meta, app_label)) 2023-04-08 06:55:06,163: 2023-04-08 06:55:06,163: File "/home/WayneMelnick/.virtualenvs/mysite-virtualenv/lib/python3.10/site-packages/django/db/models/base.py", line 369, in add_to_class 2023-04-08 06:55:06,164: value.contribute_to_class(cls, name) 2023-04-08 06:55:06,164: 2023-04-08 06:55:06,164: File "/home/WayneMelnick/.virtualenvs/mysite-virtualenv/lib/python3.10/site-packages/django/db/models/options.py", line 231, in contribute_to_class 2023-04-08 06:55:06,164: self.db_table, connection.ops.max_name_length() 2023-04-08 06:55:06,165: 2023-04-08 06:55:06,165: File "/home/WayneMelnick/.virtualenvs/mysite-virtualenv/lib/python3.10/site-packages/django/utils/connection.py", line 15, in getattr 2023-04-08 06:55:06,165: return getattr(self._connections[self._alias], item) 2023-04-08 06:55:06,165: 2023-04-08 06:55:06,166: File "/home/WayneMelnick/.virtualenvs/mysite-virtualenv/lib/python3.10/site-packages/django/utils/connection.py", line 62, in getitem 2023-04-08 06:55:06,167: conn = self.create_connection(alias) 2023-04-08 06:55:06,167: 2023-04-08 06:55:06,167: File "/home/WayneMelnick/.virtualenvs/mysite-virtualenv/lib/python3.10/site-packages/django/db/utils.py", line 193, in create_connection 2023-04-08 06:55:06,167: backend = load_backend(db["ENGINE"]) 2023-04-08 06:55:06,168: 2023-04-08 06:55:06,168: File "/home/WayneMelnick/.virtualenvs/mysite-virtualenv/lib/python3.10/site-packages/django/db/utils.py", line 113, in load_backend 2023-04-08 06:55:06,168: return import_module("%s.base" % backend_name) 2023-04-08 06:55:06,168: 2023-04-08 06:55:06,169: File "/home/WayneMelnick/.virtualenvs/mysite-virtualenv/lib/python3.10/site-packages/django/db/backends/mysql/base.py", line 17, in 2023-04-08 06:55:06,169: raise ImproperlyConfigured(
I've tried installing mysqlclient but I get a message Requirement already satisfied: mysqlclient in /usr/local/lib/python3.10/site-packages (2.1.0).
I saw in another post on stack overflow that I could use pymysql instead as long as I add import pymysql pymysql.install_as_MySQLdb()
to the init.py file. I got a message ModuleNotFoundError: No module named 'pymysql' when I attempted this. pymysql appears to have installed correctly
One thing that I can think of that might be causing the issue is that I have the free version of pythonanywhere. Is it possible I need to upgrade to a paid version in order to access these libraries? I haven't seen anything in the documentation stating this
From your traceback, it looks like you're using a virtualenv:
/home/WayneMelnick/.virtualenvs/mysite-virtualenv
However, it looks like you ran the pip install
command when you were not working in the virtualenv:
Requirement already satisfied: mysqlclient in /usr/local/lib/python3.10/site-packages (2.1.0).
In order to install something in a virtualenv like the one that you have (inside the .virtualenvs
directory, so created with mkvirtualenv
) you need to first activate it for the Bash console that you're using:
workon mysite-virtualenv
...and then run the pip install
command.