Django 1.8 - what's the difference between migrate and makemigrations?

后端 未结 8 749
说谎
说谎 2021-01-30 16:23

According to the documentation here: https://docs.djangoproject.com/en/1.8/topics/migrations/ it says:

migrate, which is responsible for applying migrations, as          


        
相关标签:
8条回答
  • 2021-01-30 17:12

    As Django's documentation says Migrations are Django’s way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema.

    makemigrations basically generates the SQL commands for preinstalled apps (which can be viewed in installed apps in settings.py) and your newly created apps' model which you add in installed apps.It does not execute those commands in your database file. So tables doesn't created after makemigrations.

    After applying makemigrations you can see those SQL commands with sqlmigrate which shows all the SQL commands which has been generated by makemigrations.

    migrate executes those SQL commands in database file.So after executing migrate all the tables of your installed apps are created in your database file.

    You can conform this by installing sqlite browser and opening db.sqlite3 you can see all the tables appears in the database file after executing migrate command.

    0 讨论(0)
  • 2021-01-30 17:16

    This is django's replacement for the old manual south way of making migrations, they can be used to catalog changes in your models and write out changes that will take place in the db.

    Migrate is basically the old syncdb but it takes into account all the migrations made by makemigrations.

    0 讨论(0)
提交回复
热议问题