有没有办法可以转换一个完整的 MyISAM数据库到 InnoDB(以一种将创建所有外键约束的方式,就像我从头开始运行 syncdb 命令一样)?
最佳答案
这可能有帮助:
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])
将其添加到文件夹 management/commands/下的应用程序中,然后您可以使用 manage.py 命令转换所有表:
python manage.py convert_to_innodb
关于mysql - 使用 Django 将现有的 MyISAM 数据库转换为 InnoDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9235704/