K
K
Karina2014-05-07 16:02:54
MySQL
Karina, 2014-05-07 16:02:54

Django. How to connect to an existing MySQL model?

There is a mysql database on the disk. I can’t figure out what to use to connect with, or it
django-admin.py syncdb
throws errors like this:

raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

But syncdb shouldn't fit here, sort of.
Here, it seems to fit,
django-admin.py migrate
but it says that the migrate command was not found. You need to install something via pip, apparently.
In settings.py this is:
DATABASES = {
    'default': {
        'NAME': '/usr/local/var/mysql/Didondo',
        'ENGINE': 'django.db.backends.mysql',
        'USER': 'root',
        'PASSWORD': '',
        'OPTIONS': {
        'autocommit': True,
        'HOST' : 'localhost',
        'PORT' : ' ',
    }
    }
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Pavel Solovyov, 2014-05-07
@iKapex

manage.py syncdb - synchronize models with the database.
Install lib:
sudo apt-get install python-mysqldb
1. First create the database manually on the Mysql server.
2. Specify the name of the database in NAME, not the full path to the database, 'NAME': 'Didondo',
3. add PASSWORD if it is installed in Mysql.
4. Run manage.py syncdb
PS manage.py migrate runs migrations if set to South

M
maxaon, 2014-05-07
@maxaon

'Error loading MySQLdb module' - The mysql-python module or similar was not installed. You may need dev packages.

E
evgenovaloff, 2017-03-11
@evgenovaloff

Under Windows, I did this:
1. Launched OpenServer (which I already had installed for PHP)
2. Registered in the "settings.py" file of the project:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'example.python',
        'USER': 'root',
        'PASSWORD': '',
    }
}

3. Created a table via phpMyAdmin
4. Started the server
python manage.py runserver

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question