Django database configuration

1: Installation and Configuration

1 1 : PIP install PyMySQL (or directly setting Pycharm, click the Add PyMySQL)
 2  
3 2 : add the following statement in a subdirectory of the same name Django project __init__.py file:
 4  from pymysql Import install_as_MySQLdb
 5  
6  install_as_MySQLdb ()
 7  # role is to make Django's ORM able to mysqldb way to invoke PyMySQL. 
. 8  
. 9  
10 . 3 : Modify DATABASES configuration information
 . 11 DATABASES = {
 12 is      ' default ' : {
 13 is          ' ENGINE ' : ' django.db.backends.mysql ' ,
 14          'The HOST ' : ' 127.0.0.1 ' ,   # database host 
15          ' PORT ' : 3306,   # database port 
16          ' the USER ' : ' the root ' ,   # database username 
. 17          ' PASSWORD ' : ' MySQL ' ,   # database user password 
18          ' NAME ' : ' django_demo '  # Database name 
19      }
 20  }
 21  
224: Create a MySQL database; default charset = utf8 must be added, otherwise the database does not support Chinese
 23 the Create Database django_demo default charset = utf8;
View Code

 

Guess you like

Origin www.cnblogs.com/wanghong1994/p/11595814.html