Reputation: 2850
Sounds fairly simple but I've been trying to do this for several days now and have hit a brick wall. Below I've listed my attempts so far, in all cases it works flawlessly when running locally, but falls over as soon as I deploy to Azure. Note that I am using an Azure website rather than a VM ( mainly because of cost implications - I'm aware that using a VM would most likely solve the problem ). The only way I've found to make this work is to use a sqlite database deployed within the project.
Things I've Tried:
1) Create a MySQL database using the azure partner clearDB. 'manage.py syncdb' works fine, can run up and use the site locally using 'manage.py runserver'. Deploy to azure and it fails with an unresolved import for Python-MySqlDb.
2) Create a SQLAzure database and use django-pyodbc-azure to connect from django. Again, syncdb / runserver work fine locally, deployed to Azure gives unresolved import for the dbapi module.
3) Use sqllite3 as db engine - works fine in both cases, but no redundancy and ( seemingly ) slow data access.
Looking at the tutorials for deploying a Django app on Azure Websites, none of them go into any detail about databases, just stopping at the point of creating a Hello World! page. I refer to: this and this
The website we're trying to deploy is running on a reserved instance. I've tried all of this with both Django 1.4 and 1.5. I'm using virtualenv / pip to make sure all dependencies are included in the site-packages I'm deploying, all of which is included in the git repository. Have also gone in via FTP to verify that all the required files are being uploaded.
SURELY - there must be a way to set this up correctly? If not, having Django as a feature of azure websites seems entirely pointless.
Any help greatly appreciated!
EDIT
Traceback from Azure error logging for the clearDB solution:
File "D:\home\site\wwwroot\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "D:\home\site\wwwroot\site-packages\django\db\backends\mysql\base.py", line 17, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
ErrorCode Access is denied.
(0x5)
Upvotes: 3
Views: 2109
Reputation: 638
I have Django and MySQL working on Azure. The MySQLdb module contains more than just the MySQLdb directory. It also contains 4 platform-specific files beginning with _mysql...
. Make sure you include those files when you push to Azure. If you don't your Django project will work locally but not remotely. You don't need to use a pure-Python MySQL adapter.
Here's a walkthrough: How to host your Django apps on Azure for free.
Upvotes: 1
Reputation: 2850
Solved - kind of:
Using a pure python mysql driver works ( as I kind of guessed it might, this being caused by an environment limitation of azure )
For future reference - this project sorted it all out for me:
https://github.com/jloic/django-mysql-pymysql
note: Azure seems not to pick up python eggs in site-packages, so I had to extract the contents into site-packages and tadaa it all worked.
Next step is to try using the cython version, although the speed of the site seems fine so far.
Upvotes: 0