- Django Design Patterns and Best Practices
- Arun Ravindran
- 175字
- 2021-06-25 21:32:10
Migrations
Migrations help you to confidently make changes to your models. Introduced in Django 1.7, migrations are essential to a methodical development workflow.
The new workflow is essentially as follows:
- The first time you define your model classes, you will need to run the following:
python manage.py makemigrations <app_label>
- This will create migration scripts in the app/migrations folder.
- Run the following command in the same (development) environment:
python manage.py migrate <app_label>
- This will apply the model changes to the database. Sometimes, questions are asked to handle the default values, renaming, and so on.
- Propagate the migration scripts to other environments. Typically, your version control tool, for example Git, will take care of this. As the latest source is checked out, the new migration scripts will also appear.
- Run the following command in these environments to apply the model changes:
python manage.py migrate <app_label>
- Whenever you make changes to the models classes, repeat step 1 to step 5.
If you omit the app_label in the commands, Django will find unapplied changes in every app and migrate them.
推薦閱讀
- TypeScript入門與實戰(zhàn)
- jQuery EasyUI網(wǎng)站開發(fā)實戰(zhàn)
- Architecting the Industrial Internet
- Hands-On Reinforcement Learning with Python
- WebRTC技術(shù)詳解:從0到1構(gòu)建多人視頻會議系統(tǒng)
- C語言程序設(shè)計實驗指導(dǎo) (第2版)
- C++語言程序設(shè)計
- Node.js 12實戰(zhàn)
- OpenStack Networking Essentials
- 軟件測試分析與實踐
- Flink核心技術(shù):源碼剖析與特性開發(fā)
- 算法精解:C語言描述
- 大話代碼架構(gòu):項目實戰(zhàn)版
- Android從入門到精通
- 歐姆龍PLC編程指令與梯形圖快速入門