What is Django's migration?

后端 未结 3 908
既然无缘
既然无缘 2021-01-21 11:56

I\'ve been wrapping my head around this concept for a while, when I start a new django project, it urges me to apply migrations:

# python manage.py runserver
Pe         


        
3条回答
  •  渐次进展
    2021-01-21 12:47

    Migrations are a great way of managing database schema changes. This has 2 main benefits (in my opinion):

    1 - If you have multiple instances of an application - development + production being the typical minimum, but could potentially be an application installed by others (either standalone or together with other Django applications), migrations allow you, the developer, to propagate database schema changes in a safe & controlled way. You can guarantee that any up-to-date version of your application (i.e., including your latest database models) will have a functioning database to match. So the general answer is that migrations solve a very common problem in a relatively elegant manner.

    2 - Specifically, as noted in another answer, there are initial migrations, even for an absolutely brand-new Django project, relating to users and permissions. Any Django application of any significance that I can think of will need these tables to function - i.e., if you don't make use of them then you are, arguably, not benefiting from much of what Django has to offer as a framework. By including migrations, you the developer can decide what database to use (SQLite, MySQL, PostgreSQL, etc.) and where that database will reside and once you have made those settings (typically in settings.py for the project), the migrations take care of the rest.

提交回复
热议问题