django framework for learning: Nine django connection mysql, sqlite

Foreword

Django provides good support for a variety of databases, including: PostgreSQL, MySQL, SQLite, Oracle . Example mysql this part to connect mysql django brief data manipulation
Django mysql even need to install drivers mysqlclient

sqlite connection

Here to pycharm5.0 version, for example

Select db.sqlite3 Right -new-Data Source

Set path , Drvier as shown in FIG.

Setting File , the URL of

 

 

Click Test Connection, the lower right corner Apply application.

mysql installation

method 1:

In python 3.x

pip install pymysql

After installation also need __init__.py add initialization code

import pymysql

pymysql.install_as_MySQLdb()

 

 

 

Method 2:

Download and install mysqlclient

pip install mysqlclient

In settings.py configuration database connection information

 

 Navicat mysql client connection

Here docker has been used to build a mysql database on a server myself, docker ps

 

 Query port number

Connect to the database

 

 

 

Create a table, database synchronization

modles.py create presoninfo

 

 Terminal migrate data:

python manage.py makemigrations

python manage.py migrate

Open navicat mysql client view

 

 

 

 Generate the database successfully

 

Guess you like

Origin www.cnblogs.com/liushui0306/p/12576118.html