Django DB migration when you're using a custom MySQL installation dir

For some reason, you installed MySQL in a different path than the default /etc/mysql/. Then if you run the Django's migrate command, it will fail because It cannot communicate with the MySQL process:

django.db.utils.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")

If that's the case, you can use the following option in your Django's configuration to indicate the socket directory of MySQL:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'OPTIONS': {
            'read_default_file': '/path/to/my.cnf',
        },
    }
}


That's it. Profit!!!