[Difference] Django2.0 python manage.py makemigrations and python manage.py migrate the

 No matter when we first created in models.py the class object of the class or attribute changes, we will use python manage.py makemigrations and two command python manage.py migrate, just from the point of view of both the command words in fact, just behind makemigrations difference and migrate the

  first models in models created in class, as shown:

 

  use the following command python manage.py makemigrations:

   


  represents one more in the blog under migations application directory files red box 001 files, let's look at what the specific content of this document is:

 

this file contents inside means that we have created a model Employee class, and pointed out that members of this class attributes id, name, and their property, we know in models.py create a model class, which corresponds to a model class is a data table, take a look at the piece performed just after the stop command database What has not changed, we want the data table is not created well, as shown below:


you can see inside the database and not the number we want to create According to the table, that that command just executed what specific statements, we can use python manage.py sqlmugrate appname file name to view:



and contents 0001 document is consistent, you can start python manage.py migrate, as shown below:



look again at the following databases:

we issued a command after executing the finger, we want to create data tables appeared, also appeared in the corresponding field

   Here we almost know, python manage.py makemigrations this command is to record all changes to our models.py, and this change will migrate to the next migrations this file to generate a file for example: 0001 files if you then have to make changes, then may generate a file is another file 0001 are not necessarily, but the command was not applied to the database, this just after the operation we have seen above, and that when we execute python manage.py migrate command the main role of the command is to effect these changes to the database to perform the migration file is to update the database migrations inside the new changes, such as creating tables, or add a field attribute

   Another thing to note is that these two commands by default is acting on global, which is carried out corresponding operation on all models following the latest changes or migrations migration file, if it is only on the part of app acts, then execute the following command:

Python manage.py makemigrations appname,

Python manage.py Migra te appname,

if it is accurate to a certain migration file, you can use:

Python manage.py the migrate appname file name
---------------------  
Author: leeyongbard  
Source: CSDN  
original: https: //blog.csdn.net/hpu_yly_bj/article/details/78928089  
copyright: This article is a blogger original article, reproduced, please attach Bowen link!

Guess you like

Origin www.cnblogs.com/fengff/p/11097361.html