久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

python - django 項目的 migrations 目錄是否應(yīng)該提交到 git

瀏覽:132日期:2022-06-29 11:39:49

問題描述

如題,本地開發(fā)環(huán)境修改 model 時,有些時候會變動好幾次,然后就生成了很多 migrations 文件。

但是部署到服務(wù)器時,服務(wù)器端應(yīng)該怎么執(zhí)行變動:

不上傳 migrations 文件,直接執(zhí)行 makemigrations 重新生成 migrations,再運(yùn)行 migrate

上傳開發(fā)時的 migrations 文件,然后直接執(zhí)行 migrate

上面兩種方法該選哪一種?為什么?

問題解答

回答1:

按照官方的說法,應(yīng)該提交,并且在服務(wù)器端應(yīng)該直接執(zhí)行 migrate,無需再次生成。

You should think of migrations as a version control system for your database schema. makemigrations is responsible for packaging up your model changes into inpidual migration files - analogous to commits - and migrate is responsible for applying those to your database.

The migration files for each app live in a “migrations” directory inside of that app, and are designed to be committed to, and distributed as part of, its codebase. You should be making them once on your development machine and then running the same migrations on your colleagues’ machines, your staging machines, and eventually your production machines.

中文翻譯:

你可以想象 migrations 相當(dāng)一個你的數(shù)據(jù)庫的一個版本控制系統(tǒng)。makemigrations 命令負(fù)責(zé)保存你的模型變化到一個遷移文件 - 和 commits 很類似 - 同時 migrate負(fù)責(zé)將改變提交到數(shù)據(jù)庫。

每個 app 的遷移文件會保存到每個相應(yīng) app 的“migrations”文件夾里面,并且準(zhǔn)備如何去執(zhí)行它, 作為一個分布式代碼庫。 每當(dāng)在你的開發(fā)機(jī)器或是你同事的機(jī)器并且最終在你的生產(chǎn)機(jī)器上運(yùn)行同樣的遷移,你應(yīng)當(dāng)再創(chuàng)建這些文件。

回答2:

建議提交到版本庫中。

回答3:

我目前是不同步到遠(yuǎn)程庫的。因為開發(fā)過程中要頻繁的對model進(jìn)行修改,會生成很多migrations文件,不好控制migrate不出錯;發(fā)布程序之前,首先確認(rèn)是否進(jìn)行model更新,如果有的話先進(jìn)行makemigrations然后migrate,由于本地已經(jīng)測試完成,所以不容易出現(xiàn)一些奇怪的同步問題。

回答4:

為什么不提交之前把migrations里新生成的多次變動刪了 重新makemigrations一下然后提交版本庫呢

回答5:

可是在本地,添加字段然后再刪除等等一些無用的操作,最后可能數(shù)據(jù)庫沒有任何變動,那么這些 migrations 也得提交到服務(wù)器上再運(yùn)行一遍?

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 天水市| 灵石县| 剑河县| 合肥市| 甘肃省| 高清| 黔东| 华亭县| 阳山县| 德阳市| 满洲里市| 彰化县| 新安县| 乐陵市| 清水县| 宁河县| 新龙县| 顺义区| 新泰市| 吴川市| 特克斯县| 天台县| 南澳县| 镇远县| 米林县| 壶关县| 密云县| 乌什县| 鄂温| 饶平县| 弋阳县| 余干县| 河津市| 黄平县| 太仓市| 高清| 龙岩市| 涿鹿县| 四会市| 灵台县| 兴城市|