How to get started with Django on top of Python 3.4 + MySQL (MariaDB) 5.5


Django ( is an amazing and simple Python MVC framework. Here is how you get started with newer version of MySQL and Python.

Vagrant (optional)

Eventually start out with a fresh VM (Ubuntu + Python3 environment) with this Vagrant box:


Create a new Python 3.4 isolated environment with Virtualenv (

$ virtualenv-3.4 djangoenv

Activate the new Python environment (djangoenv):

$ source djangoenv/bin/activate

Install django lib with pip:

$ pip install django

Install mariadb version 5.5:

$ apt-get install  mariadb-server-5.5

Test if django is installed properly:

$ python -c "import django; print(django.get_version())"

Check if Python and MySQL versions are correct:

$ mysql -V
mysql  Ver 15.1 Distrib 5.5.44-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
$ python -V
Python 3.4.0

Start your new django project:

$ django-admin startproject mysite

MySQL Engine

Run runserver or migrate command:

$ python migrate
$ python runserver 8080

You will see the following error:

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'

If you read the documentation, you will see that the native MySQLdb driver doesn't support Python 3. The trick is to use the mysql.connector instead. Read more in the documentation:

Change the ENGINE to mysql.connector.django in your project settings(.py):

 $ vi mysite/mysite/
 78     'default': {
 79         'NAME': 'djangotest',
 80         'ENGINE': 'mysql.connector.django',
 81         'HOSTNAME': 'localhost',
 82         'USER': 'root',
 83         'PASSWORD': 'testtest123!',
 84         'OPTIONS': {
 85             'autocommit': True,
 86         },
 87     }
 88 }

Now try again to create neccessary db stuff for the default APPS in Django:

$ python migrate
August 14, 2015 - 08:12:20
Django version 1.8.3, using settings 'mysite.settings'
Starting development server at
Quit the server with CONTROL-C.
^C(djangovirtualenv)root@vagrant-ubuntu-trusty-64:~/mysite# python migrate
Operations to perform:
  Synchronize unmigrated apps: staticfiles, messages
  Apply all migrations: auth, sessions, admin, contenttypes
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
  Installing custom SQL...
Running migrations:
  Rendering model states... DONE
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying sessions.0001_initial... OK

Ready to code

Now it should work. You should be ready to start coding your django apps:

$ python startapp appname