简体   繁体   English

django 中的“ python manage.py migrate ”到底是做什么的?

[英]what does “ python manage.py migrate ” in django do exactly?

I am new to Django, and the tutorial directly applied this command without explanation.我是Django新手,教程直接应用了这个命令,不做解释。

After searching, I found out it's calling migrations in Django, but didn't understand it either as I am a complete newbie at this.搜索后,我发现它在 Django 中调用迁移,但由于我是一个完全新手,所以我也不明白。

What does the python manage.py migrate command do exactly? python manage.py migrate命令究竟做了什么? What are migrations?什么是迁移?

If your database doesn't exist yet, migrate creates all the necessary tables to match your model definitions.如果您的数据库尚不存在,则migrate创建所有必要的表以匹配您的 model 定义。

Otherwise if the database already exists, migrate brings the existing table definitions to be in sync with the model definitions -- ie maybe you added a field to one of your models, so migrate would add that column to the database table.否则,如果数据库已经存在,那么migrate会使现有的表定义与 model 定义同步——即,也许您在其中一个模型中添加了一个字段,因此migrate会将该列添加到数据库表中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM