DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': '數據庫名稱', 'USER': '數據庫用戶名', 'PASSWORD': '數據庫密碼', 'HOST': '主機地址', 'POST': '端口號', } } INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', '你的應用名稱', ]
import pymysql pymysql.install_as_MySQLdb()
3.1報錯:django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.3 or newer is required; you have 0.7.11.Nonepython
解決方法:C:\Users\adong\AppData\Local\Programs\Python\Python36\Lib\site-packages\Django-2.0.3-py3.6.egg\django\db\backends\mysql\base.pymysql
註釋掉:sql
if version < (1, 3, 3): raise ImproperlyConfigured("mysqlclient 1.3.3 or newer is required; you have %s" % Database.__version__)
3.2修改:C:\Users\adong\AppData\Local\Programs\Python\Python36\Lib\site-packages\Django-2.0.3-py3.6.egg\django\db\backends\mysql\operations.py數據庫
query = query.encode(errors='replace')
from django.db import models class user(models.Model):#建立一個表 id = models.AutoField(primary_key=True)#自增加id user = models.CharField(max_length=20) password = models.CharField(max_length=20) email = models.EmailField() phone = models.IntegerField() perorg = models.IntegerField()
python manage.py makemigrations 應用名 python manage.py migrate
4.1錯誤:【8001】Could not create connection to database server. Attempted reconnect 3 times. Giving up.django
解決方法:將URL改爲這個:jdbc:mysql://localhost:3306/【表名】?useSSL=false&serverTimezone=UTCsession