将 Django 项目从 MySQL 迁移到 PostgreSQL 的最简单方法 [英] The easiest way to migrate a Django project from MySQL to PostgreSQL

查看:30
本文介绍了将 Django 项目从 MySQL 迁移到 PostgreSQL 的最简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的 Django 项目的数据库从 MySQL 转换为 PostgreSQL.不幸的是,我不能只使用 Django 的dumpdata"和loaddata"管理命令,因为我的数据库表太大了.我已经阅读了文章 http://www.ofbrooklyn.com/2010/07/18/migrating-django-mysql-postgresql-easy-way/,但似乎要在实践中使用这种方法,我仍然需要将它变成类似在复制模型实例和重置序列时迭代可用模型的管理命令.此外,它似乎也不是很快,因为它会在每个模型实例上发出 save().

I would like to convert my Django project's database from MySQL to PostgreSQL. Unfortunately, I can't just use Django's "dumpdata" and "loaddata" management commands because my database tables are too big. I already read the article http://www.ofbrooklyn.com/2010/07/18/migrating-django-mysql-postgresql-easy-way/, but it seems that to use this method in practice I'll still need to turn it into something like a management command that iterates over available models when it copies model instances and when resets sequences. Besides, it doesn't seem very fast either because it issues save() on each model instance.

有没有更好的迁移方式?实际上,我更喜欢做mysqldump",以某种方式将转储从 MySQL 转换为 PostgreSQL 格式,然后将其加载到 PostgreSQL.您会推荐什么软件来执行这种转储转换并正确地将 MySQL 数据类型转换为 PostgreSQL 数据类型,例如 tinyint(1) 到 boolean?

Is there a better way to migrate? Actually, I would prefer to do "mysqldump", convert the dump from MySQL to PostgreSQL format somehow and then load it to PostgreSQL. What piece of software would you recommend that could perform such dump conversion and correctly convert from MySQL data types to PostgreSQL ones, for example tinyint(1) to boolean?

编辑感谢大家的帮助.我使用 https://github.com/maxlapshin/mysql2postgres 实用程序成功迁移了我的数据库.但是,在导入转储后,我仍然必须自己重置生成的 PostgreSQL 数据库中的序列.

Edit Thanks everyone for your help. I successfully migrated my database using https://github.com/maxlapshin/mysql2postgres utility. However, I still had to reset sequences in the resulting PostgreSQL database myself after importing the dump.

推荐答案

它有几个转换器,例如 Ruby 中的这个:https://github.com/maxlapshin/mysql2postgres

There are several converters for it, for example this one in Ruby: https://github.com/maxlapshin/mysql2postgres

这篇关于将 Django 项目从 MySQL 迁移到 PostgreSQL 的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆