settings
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'py',
'HOST': '127.0.0.1',
'USER': 'root',
'PASSWORD':'19970223',
'PORT':3306
}
}
App.models
from django.db import models
class User(models.Model):
uid = models.AutoField(primary_key=True)
username = models.CharField(max_length=30,unique=True)
password = models.CharField(max_length=128)
regtime = models.DateTimeField(auto_now_add=True)
class Meta:
db_table = 'user'
mysqlclient(不能使用!)
pip install mysqlclient
python manage.py makemigrations
python manage.py migrate
pymysql
init
import pymysql
pymysql.install_as_MySQLdb()
base
operations
if query is not None:
query = query.encode(errors='replace')