如何将Django模型从mysql迁移到sqlite(或任何两个数据库系统之间)? [英] How to migrate Django models from mysql to sqlite (or between any two database systems)?

查看:178
本文介绍了如何将Django模型从mysql迁移到sqlite(或任何两个数据库系统之间)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在生产中使用了一个使用MySQL的Django部署。

I have a Django deployment in production that uses MySQL.

我想使用SQLite进一步开发,所以我想将我现有的数据导入到SQLite数据库。我

I would like to do further development with SQLite, so I would like to import my existing data to an SQLite database. I

有一个shell脚本这里将一般的MySQL转储转换为SQLite,但它对我来说无效(显然一般问题不容易)。

There is a shell script here to convert a general MySQL dump to SQLite, but it didn't work for me (apparently the general problem isn't easy).

我认为这样做使用Django模型必须要容易得多。你会如何做到这一点有没有人有任何脚本来做到这一点?

I figured doing this using the Django models must be much easier. How would you do this? Does anyone have any script to do this?

推荐答案

使用

manage.py dumpdata > your_file.json

docs.djangoproject.com/en/dev/ref/django-admin/#django-admin-dumpdatarel =noreferrer> docs )。

to export your data from the production system (docs).

然后移动开发系统上的文件并运行

Then move the file on the development system and run

manage.py loaddata your_file.json

您也可以将该文件放在your_app / fixtures文件夹中,名称为initial_data.json,当您运行manage .py syncdb( docs )。

You can also put the file in your_app/fixtures folder with name "initial_data.json" and it will be automatically loaded when you run "manage.py syncdb" (docs).

这篇关于如何将Django模型从mysql迁移到sqlite(或任何两个数据库系统之间)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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