3. Django connects to mysql database and installs mysqldb driver error solution

1. Set the connection database in setting.py

  • DATABASES = {
    'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'djangotest',
    'USER':'root',
    'PASSWORD':'root',
    'HOST':'127.0.0.1',
    'PORT':'3306'
    }
    }
  • When using migrate to generate a data table, it will prompt that there is no driver connected to Mysqldb, then you need to install the driver
  • pip install mysql-python, installed in the windows environment, many errors will appear: Microsoft Visual C++ 9.0 is required.
  • The general explanation on the Internet is that reinstalling mysql and installing mysql is to choose to install the C++ compiler. . .

    Although I haven't tried it, it definitely won't work. I just want to install a package that allows python to connect to mysql remotely. What about local mysql? Some explanations are really misleading.

    But the error message also thanked the lack of the relevant environment of C++, and later found the method on the Internet: the
    method is as follows:

    1. Download the corresponding package version at http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python, if it is win7 64-bit 2.7 version of python, download it

    MySQL_python-1.2.5-cp27-none-win_amd64.whl

    2. Enter the download directory in the virtual environment and use pip to install, such as:

  •  

  •  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324645023&siteId=291194637