I was trying to run python manage.py run server while working with Django after changing my settings.py from this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
to this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'storefront',
}
}
But I was getting this error:
File "/Users/aditi/.local/share/virtualenvs/storefront-4vgosAeV/lib/python3.12/site-packages/django/db/backends/mysql/base.py", line 16, in <module>
import MySQLdb as Database
File "/Users/aditi/.local/share/virtualenvs/storefront-4vgosAeV/lib/python3.12/site-packages/MySQLdb/__init__.py", line 24, in <module>
version_info, _mysql.version_info, _mysql.__file__
^^^^^^
NameError: name '_mysql' is not defined
This is what my __init__.py looks like:
try:
from MySQLdb.release import version_info
from . import _mysql
assert version_info == _mysql.version_info
except Exception:
raise ImportError(
"this is MySQLdb version {}, but _mysql is version {!r}\n_mysql: {!r}".format(
version_info, _mysql.version_info, _mysql.__file__
)
)
I downloaded MySQL from this link, the x86 DMG option: https://dev.mysql.com/downloads/mysql/
I have Sonoma 14.3. I am running Python 3.12.7. Please let me know how I can fix this error.
I tried adding this to my .zshrc file:
export PATH="/usr/local/mysql/bin:$PATH"
But it did not work.
UPDATE: I got it to work with PyMySQL, thank you for the help everyone!