First, the configuration database
1) django default support sqlite, mysql, oracle, postgresql database.
- sqlite: django sqlite database used by default, the default comes sqlite database-driven, engine name: django.db.backends.sqlite3
- mysql: engine name: django.db.backends.mysql
2) mysql driver
- MySQLdb(mysql python)
- mysqlclient
- MySQL
- PyMySQL (pure mysql driver's python)
3) In django project will use the default sqlite database, the following settings in settings where:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } }
If we want to change the database such as mysql, you need to be modified as follows:
= {DATABASES 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'Django_ORM', # your database name 'USER': 'root', # your database username ' pASSWORD ':' mysql ', # your database password ' hOST ': '10 .0.0.12', # your database host, blank defaults to localhost 'pORT': '3306', # your database port } }
note:
#NAME that is the name of the database, the database must have been created before mysql connection, and db.sqlite3 under the above project sqlite database is created automatically #USER and PASSWORD are the user name and password for the database. # After setting, before restarting our Django project, we need to activate our mysql. Then, start the project, will complain: NO Module named MySQLdb # This is because the default django import your drive is MySQLdb, but MySQLdb for py3 a big problem, so we need to drive is PyMySQL # So, we just need to find the name of the project __init__ under the file, which is written: Import pymysql pymysql.install_as_MySQLdb () # other error https://blog.csdn.net/lijing742180/article/details/91966031