Django 同步数据库

 


$ 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是非常类似的

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值