版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38375620/article/details/85418716
$ python manage.py migrate #命令行运行该命令
因为我们已经执行过该命令会出现如下提示
Operations to perform:
Apply all migrations: admin, contenttypes, sessions, auth
Running migrations:
No migrations to apply.
Your models have changes that are not yet reflected in a migration, and so won't be applied.
Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
那么现在需要执行下面的命令
$ python manage.py makemigrations
#得到如下提示
Migrations for 'article':
0001_initial.py:
- Create model Article
现在重新运行以下命令
$ python manage.py migrate
#出现如下提示表示操作成功
Operations to perform:
Apply all migrations: auth, sessions, admin, article, contenttypes
Running migrations:
Applying article.0001_initial... OK
migrate命令按照app顺序建立或者更新数据库, 将
models.py
与数据库同步
Django Shell
现在我们进入Django中的交互式shell来进行数据库的增删改查等操作
$ python manage.py shell
Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 5 2014, 20:42:22)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>>
这里进入Django的shell和python内置的shell是非常类似的