将 Django DB 从 SQLite 迁移到 MySQL 的最佳方法是什么?
我需要将我的数据库从 sqlite 迁移到 mysql,而各种工具/脚本对我来说太多了,无法轻松找到最安全、最优雅的解决方案。
这对我来说似乎很好 http://djangosnippets.org/snippets/14/ 但似乎是 3自从获得令人担忧的更新以来已经有很多年了。
您能推荐一个已知对 Django 1.1.1 可靠的解决方案吗?
I need to migrate my db from sqlite to mysql, and the various tools/scripts out there are too many for me to easily spot the safest and most elegant solution.
This seemed to me nice http://djangosnippets.org/snippets/14/ but appears to be 3 years since getting an update which is worrying..
Can you recommend a solution that is known to be reliable with Django 1.1.1 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
执行:
接下来,将settings.py更改为mysql数据库。
最后:
Execute:
Next, change your settings.py to the mysql database.
Finally:
经过一番努力搜索后,我遇到了几个问题,我希望未来寻找答案的人会发现这些问题有用。
我的公式是
python manage.py migrate --run-syncdb
排除 contentype 数据在 shell 中使用此代码段
python manage.py shell
从 django.contrib.contenttypes.models 导入 ContentType
ContentType.objects.all().delete()
quit()
python manage.py loaddata datadump.json
希望对您有所帮助!
After some hard searching I got several problems that I hope future answer looking people will find useful.
my formula is
python manage.py dumpdata > datadump.json
python manage.py migrate --run-syncdb
Exclude contentype data with this snippet in shell
python manage.py shell
from django.contrib.contenttypes.models import ContentType
ContentType.objects.all().delete()
quit()
python manage.py loaddata datadump.json
Hope that will help you!
这是避免其他地方描述的
ContentType
问题的更简洁的方法:然后:
This is a neater way to avoid the
ContentType
issues described elsewhere:Then:
从 sqlite 迁移到 MySQL 所需的(更完整的)步骤列表,YMMV:
SET GLOBAL FOREIGN_KEY_CHECKS = 0;
从 django.contrib.contenttypes.models 导入 ContentType
ContentType.objects.all().delete()
quit()
cat datadump.json |
cat datadump.json | python -m json.tool > datadump_pretty.json
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql_tzinfo_to_sql mysql -D mysql -P 1234 -u root -p --protocol=tcp
mysql -P 1234 -u root -p -e "flushtables" --protocol=tcp
A (fuller) list of the steps I needed for moving from sqlite to MySQL, YMMV:
SET GLOBAL FOREIGN_KEY_CHECKS = 0;
from django.contrib.contenttypes.models import ContentType
ContentType.objects.all().delete()
quit()
cat datadump.json | python -m json.tool > datadump_pretty.json
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -D mysql -P 1234 -u root -p --protocol=tcp
mysql -P 1234 -u root -p -e "flush tables" --protocol=tcp