python 您最喜欢在 Django 中管理数据库迁移的解决方案是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/426378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is your favorite solution for managing database migrations in django?
提问by MiniQuark
I quite like Rails' database migration management system. It is not 100% perfect, but it does the trick. Django does not ship with such a database migration system (yet?) but there are a number of open source projects to do just that, such as django-evolution and south for example.
我非常喜欢 Rails 的数据库迁移管理系统。它不是 100% 完美的,但它确实有效。Django 没有附带这样的数据库迁移系统(还没有?)但是有许多开源项目可以做到这一点,例如 django-evolution 和 south。
So I am wondering, what database migration management solution for django do you prefer? (one option per answer please)
所以我想知道,您更喜欢哪种 django 数据库迁移管理解决方案?(请为每个答案选择一个)
采纳答案by akaihola
回答by cwadding
If you are using SQLAlchemyas your ORM then the de facto standard is Alembic.
如果您使用SQLAlchemy作为 ORM,那么事实上的标准是Alembic。
Another alternative that haven't been mentioned is yoyo-migrations.
另一个没有提到的替代方法是yoyo-migrations。
回答by Brian Clapper
We use Django at work, and we've been using dmigrations. While it has its quirks, it's been useful so far. Some features:
我们在工作中使用 Django,并且我们一直在使用dmigrations。虽然它有它的怪癖,但到目前为止它一直很有用。一些特点:
- It uses a table in the database to keep track of which migrations have been applied.
- Because it knows which ones have been applied, you can migrate up and back down.
- It integrates with
manage.py
as a command. - The individual migration scripts are Python, but if your migration logic is pure SQL, dmigrationsmakes it easy to just can the SQL and have it executed.
- 它使用数据库中的一个表来跟踪已应用的迁移。
- 因为它知道应用了哪些,所以您可以向上和向下迁移。
- 它集成
manage.py
为一个命令。 - 单独的迁移脚本是 Python,但如果您的迁移逻辑是纯 SQL,则dmigrations可以轻松地只使用 SQL 并执行它。
One problem is that it only currently supports MySQL. However, one of our guys make a local hack to it to support PostgreSQL, which we use. As I recall, the hack wasn't all that extensive, so it shouldn't be terribly difficult to hack it up to support other RDBMSs.
一个问题是它目前只支持 MySQL。但是,我们的一个人对其进行了本地破解以支持我们使用的 PostgreSQL。我记得,hack 并不是那么广泛,因此将它修改为支持其他 RDBMS 应该不是非常困难。
回答by MiniQuark
I like django-evolution:
我喜欢django-evolution:
pros:
优点:
- clean design
- no SQL needed
- flexible
- trivial to install
- easy to use
- 干净的设计
- 不需要 SQL
- 灵活的
- 安装很简单
- 使用方便
cons:
缺点:
- migrations are not fixed in the codebase
- a risk exists of accidently running a migration twice
- 代码库中未修复迁移
- 存在意外运行两次迁移的风险
回答by Van Gale
Besides South, dmigrations, django-evolution, and Migratory I thought I would add simplemigrationsas another tool I've seen for automating Django migrations.
除了 South、dmigrations、django-evolution 和 Migratory,我想我会添加simplemigrations作为我见过的另一个用于自动化 Django 迁移的工具。
I've used three of these in the past but do migrations by hand now. I'm thinking about trying South again due to the latest features added.
我过去使用过其中的三个,但现在手动进行迁移。由于添加了最新功能,我正在考虑再次尝试 South。
回答by Marcin
回答by mondaini
I've been using simple-db-migrate
我一直在使用simple-db-migrate
Pros:
优点:
- it allows me to rollback the migrations (IDK if other do this too).
- integrates with manage.py
- everyone that knows SQL can create a migration
- it doesn't run a migration twice: the application writes the migration information(timestamp, query, etc.) on a table
- 它允许我回滚迁移(IDK,如果其他人也这样做)。
- 与 manage.py 集成
- 每个知道 SQL 的人都可以创建迁移
- 它不会运行两次迁移:应用程序在表上写入迁移信息(时间戳、查询等)
Cons:
缺点:
- if you add a migration with a lower timestamp than the latest migration installed, this migration doesn't run
- Only MySQL is supported
- 如果您添加时间戳低于安装的最新迁移的迁移,则此迁移不会运行
- 仅支持 MySQL