What is Django's migration?

后端 未结 3 912
既然无缘
既然无缘 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:42

    The migrate command takes all the migrations that haven’t been applied (Django tracks which ones are applied using a special table in your database called django_migrations) and runs them against your database - essentially, synchronizing the changes you made to your models with the schema in the database.

    Migrations are very powerful and let you change your models over time, as you develop your project, without the need to delete your database or tables and make new ones - it specializes in upgrading your database live, without losing data. We’ll cover them in more depth in a later part of the tutorial, but for now, remember the three-step guide to making model changes:

    Change your models (in models.py).

    Run python manage.py makemigrations to create migrations for those changes

    Run python manage.py migrate to apply those changes to the database.

    The reason that there are separate commands to make and apply migrations is because you’ll commit migrations to your version control system and ship them with your app; they not only make your development easier, they’re also usable by other developers and in production.

提交回复
热议问题