django的makemigrations和migrate分别做了什么

建立了django的modle.py文件后,在pycharm,点击tool–run manage.py task 首先要执行makemigrations,这个时候可以看到以下类似的内容:

manage.py@mxproject > makemigrations
"F:\Program Files (x86)\JetBrains\PyCharm 5.0.3\bin\runnerw.exe" "F:\Program Files (x86)\Python3\Scripts\mxenv\Scripts\python.exe" "F:\Program Files (x86)\JetBrains\PyCharm 5.0.3\helpers\pycharm\django_manage.py" makemigrations D:/python/mxproject
Migrations for 'courses':
  0001_initial.py:
    - Create model Course
    - Create model CourseResource
    - Create model Lesson
    - Create model Video
Migrations for 'organization':
  0001_initial.py:
    - Create model CityDict
    - Create model CourseOrg
    - Create model Teacher
Migrations for 'operation':
  0001_initial.py:
    - Create model CourseComments
    - Create model UserAsk
    - Create model UserFavorite
    - Create model UserMessage
Migrations for 'users':
  0002_banner_emailverifyrecord.py:

这时其实是在该app下建立 migrations目录,并记录下你所有的关于modes.py的改动,比如0001_initial.py,
django的makemigrations和migrate分别做了什么_第1张图片

但是这个改动还没有作用到数据库文件,数据库没有增加新的表

接着执行migrate,这时候才真的把作用到数据库文件,产生对应的表

manage.py@mxproject > migrate
"F:\Program Files (x86)\JetBrains\PyCharm 5.0.3\bin\runnerw.exe" "F:\Program Files (x86)\Python3\Scripts\mxenv\Scripts\python.exe" "F:\Program Files (x86)\JetBrains\PyCharm 5.0.3\helpers\pycharm\django_manage.py" migrate D:/python/mxproject
Operations to perform:
  Apply all migrations: sessions, users, contenttypes, courses, organization, operation, admin, auth
Running migrations:
  Rendering model states... DONE
  Applying courses.0001_initial... OK
  Applying operation.0001_initial... OK
  Applying organization.0001_initial... OK
  Applying users.0002_banner_emailverifyrecord... OK

Process finished with exit code 0

django的makemigrations和migrate分别做了什么_第2张图片

你可能感兴趣的:(django模型(三))