使用Django将现有的MyISAM数据库转换为InnoDB [英] Converting an existing MyISAM database to InnoDB with Django

查看:292
本文介绍了使用Django将现有的MyISAM数据库转换为InnoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将完整的MyISAM数据库转换为InnoDB(以一种方式创建所有外键限制,就像从头开始运行syncdb命令一样)?

Is there anyway I can convert a full populated MyISAM database to InnoDB (in a way that will create all foreign key contraints, same way it would be if I ran the syncdb command from the beginning)?

推荐答案

可能有帮助:

from django.core.management.base import BaseCommand
from django.db import connections


class Command(BaseCommand):

    def handle(self, database="default", *args, **options):

        cursor = connections[database].cursor()

        cursor.execute("SHOW TABLE STATUS")

        for row in cursor.fetchall():
            if row[1] != "InnoDB":
                print "Converting %s" % row[0],
                print cursor.execute("ALTER TABLE %s ENGINE=INNODB" % row[0])

添加这可以通过文件夹管理/命令/你的应用程序。然后,您可以使用manage.py命令转换所有表:

Add that to your app under the folders management/commands/ Then you can convert all your tables with a manage.py command:

python manage.py convert_to_innodb

这篇关于使用Django将现有的MyISAM数据库转换为InnoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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