Django1.7+python 2.78+pycharm Configure MySQL Database tutorial _python

Source: Internet
Author: User

After you configure virtualenv and virtualenvwrapper, use Pycharm to create a new project. Then the problem to be faced with, has been using SQLite as a development database to learn, according to the principles of the previous tutorial, as if the development environment to the production environment as much as possible, so now want to try to use a more likely to deploy in the production environment MySQL database development.

I thought it was a very easy thing to do, but I didn't expect to get into some trouble.

According to a pass Baidu, the search out of the plan is probably:

MySQLdb
MySQL installation time with the connector
Pymysql

MySQLdb
The first Django official recommendation was the database link library that Django officially recommended, and it was my first attempt. However, the installation of the time can not find suitable for 64-bit, python2.78 installation files! Through an article introduced modify reluctantly installed on the support of 2.7 version, the results are always used when Unicode error, MySQL database also according to the tutorial set into the UTF8 code, had to forget

2, connector with the

It's an official version, but according to the official installation method, there's always no Mysql.connector.django this module .... Don't understand why. Look for the successful installation of the students and then met the Chinese Unicode error .... Residual reading

3,pymysql

This is a blog about Python3 trial Django-mysql solution. At first because the unofficial did not make, it is an accident simple success ...

Add in Project's inti.py:

Copy Code code as follows:

Import Pymysql
Pymysql.install_as_mysqldb ()
Settings

DATABASES = {
' Default ': {
' ENGINE ': ' Django.db.backends.mysql ', #数据库引擎
' NAME ': ' Django ', #数据库名
' User ': ' User ', #用户名
' PASSWORD ': ' password! ', #密码
' HOST ': ' localhost ', #数据库主机, defaults to localhost
' PORT ': ' 3306 ', #数据库端口, MySQL defaults to 3306
' OPTIONS ': {
' Autocommit ': True,
},
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.