37👍
three cheers for @traviscline’s suggestion to go with pymysql. his suggestion was based on this post from mozilla. all it takes is a simple patch to your manage.py file
#!/usr/bin/env python
+try:
+ import pymysql
+ pymysql.install_as_MySQLdb()
+except ImportError:
+ pass
changing the import in your settings file, and monkeypatch() since pymysql is a pure python driver.
travis mentioned that he tests for compatability by changing the imports and running the unittests for pymysql, mysqldb, and myconnpy.
note that there are already examples of finer details to watch out for – but overall this is an elegant, maintainable solution. i will update when i get this running in production!
-1👍
I was successful in getting pymysql to work with Django doing the following :
- Comment out the try-except block at the beginning of the base.py file, where MySQLdb is imported.
-
Add the following four lines to base.py
try: import pymysql as Database except ImportError: pass
-
As mentioned in the link that egbutter posted, go to the base.py file and find-replace
MySQLdb
withpymysql
at relevant portions of the file, i.e. don’t bother changing the error messages (you could, but that’s up to you). -
Save base.py, and run the following command from the apt location to see the server start up.
python manage.py runserver
- [Django]-How can I tell the Django ORM to reverse the order of query results?
- [Django]-Django settings per application – best practice?
- [Django]-Override save on Django InlineModelAdmin