当通过 Model 声明完表结构后,Django 可以自动将 Model 声明转换成DB Schema,进而自动写入 DB 中。
在>=1.7 的 Django 中,可以使用以下方法来生成 DB schema:
$ python manage.py makemigrations
$ python manage.py migrate
The makemigrations
command looks at all your available models and creates migrations for whichever tables don’t already exist. migrate
runs the migrations and creates tables in your database, as well as optionally providing much richer schema control.
在 1.7 之前的版本,使用:
$ python manage.py syncdb
Reference
- https://docs.djangoproject.com/en/2.2/topics/migrations
- https://stackoverflow.com/questions/20250123/django-error-unknown-command-makemigrations
FEATURED TAGS
algorithm
algorithmproblem
architecturalpattern
architecture
aws
c#
cachesystem
codis
compile
concurrentcontrol
database
dataformat
datastructure
debug
design
designpattern
distributedsystem
django
docker
domain
engineering
freebsd
git
golang
grafana
hackintosh
hadoop
hardware
hexo
http
hugo
ios
iot
java
javaee
javascript
kafka
kubernetes
linux
linuxcommand
linuxio
lock
macos
markdown
microservices
mysql
nas
network
networkprogramming
nginx
node.js
npm
oop
openwrt
operatingsystem
padavan
performance
programming
prometheus
protobuf
python
redis
router
security
shell
software testing
spring
sql
systemdesign
truenas
ubuntu
vmware
vpn
windows
wmware
wordpress
xml
zookeeper