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:
1)Change your models (in models.py).
2)Run python manage.py makemigrations to create migrations for those changes
3)Run python manage.py migrate to apply those changes to the database.
Django修改Model,在不删除数据库的前提下
最新推荐文章于 2024-07-24 17:34:46 发布
本文介绍了一种强大的数据库迁移方法,可以在不删除现有数据库或丢失数据的情况下调整模型结构。通过三个步骤实现:修改 models.py 中的模型定义;运行 python manage.py makemigrations 创建迁移文件;最后运行 python manage.py migrate 应用更改。
1万+

被折叠的 条评论
为什么被折叠?



