0

settings.py:

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

my.cnf:

[client]
database=fake
host=127.0.0.1
port=3306
user=fake
password=fake
default-character-set=utf8

These files are in the same directory of my Django project. (The actual my.cnf has real credentials). I have installed mysqlclient. However, when I try to runserver I get the error

Traceback (most recent call last):
  File "//anaconda/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "//anaconda/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "//anaconda/lib/python2.7/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
    six.reraise(*_exception)
  File "//anaconda/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "//anaconda/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "//anaconda/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "//anaconda/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "//anaconda/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "//anaconda/lib/python2.7/site-packages/django/contrib/auth/models.py", line 4, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "//anaconda/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 49, in <module>
    class AbstractBaseUser(models.Model):
  File "//anaconda/lib/python2.7/site-packages/django/db/models/base.py", line 108, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
  File "//anaconda/lib/python2.7/site-packages/django/db/models/base.py", line 299, in add_to_class
    value.contribute_to_class(cls, name)
  File "//anaconda/lib/python2.7/site-packages/django/db/models/options.py", line 263, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "//anaconda/lib/python2.7/site-packages/django/db/__init__.py", line 36, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "//anaconda/lib/python2.7/site-packages/django/db/utils.py", line 212, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "//anaconda/lib/python2.7/site-packages/django/db/utils.py", line 116, in load_backend
    return import_module('%s.base' % backend_name)
  File "//anaconda/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "//anaconda/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 28, in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(//anaconda/lib/python2.7/site-packages/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
  Referenced from: //anaconda/lib/python2.7/site-packages/_mysql.so
  Reason: image not found

What configuration step(s) have I missed or farked up?

1 Answer 1

1

This looks like a possible duplicate of this question and this one

It looks like the library is not where it should be. From your previous question it looks like you installed it at

/usr/local/mysql/

but Django is expecting it to be at /usr/lib/

Creating the symlinks like in the other questions should fix this for you:

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib

sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Looks like I still have a few more hurdles to cross, but this answer got me past THAT error message.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.