1、數(shù)據(jù)庫配置
1.1荆忍、連接配置
mysite/settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django',
'USER': 'root',
'PASSWORD': '',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
不同數(shù)據(jù)庫使用不同的ENGINE格带,視開發(fā)環(huán)境修改。
1.2刹枉、是否有數(shù)據(jù)庫連接池配置叽唱??微宝?
2棺亭、數(shù)據(jù)遷移migrate
# 1. 創(chuàng)建更改的文件
python manage.py makemigrations
# 2. 將生成的py文件應(yīng)用到數(shù)據(jù)庫
python manage.py migrate
3、API
- p.save()
- Poll.objects.all()
- Poll.objects.filter(title='dd')
- Poll.objects.get()
- Poll.objects.get(pk=1)