【Django】Django ORM - 使 DB Schema 生效

Posted by 西维蜀黍 on 2019-11-17, Last Modified on 2021-10-02

当通过 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


TOC