【发布时间】:2016-03-31 10:31:35
【问题描述】:
class Command(BaseCommand):
args = 'Arguments is not needed'
help = 'Django admin custom command poc.'
def handle(self, *args, **options):
db_alias = options.get('olddb')
db_entry = settings.DATABASES.get(db_alias)
output = open(output_filename,'w')
cmd = ["mysqldump",
"-u", db_entry.get('USER'),
"-p%s" % db_entry.get('PASSWORD'),
"-h", db_entry.get('HOST'),
db_entry.get('NAME')]
subprocess.call(cmd, stdout=output)
我在这里转储我的数据库(olddb)。转储的语法是否正确? 我正在以“python manage.py sqldump”的形式运行命令。 我当前的数据库中有一个架构。如何将数据迁移到新数据库?我没有 了解新数据库中存在的架构是什么。如果错误来回滚,则在迁移数据时 必须在新数据库中完成。
或任何其他获得更多信息的好文章?
【问题讨论】:
标签: mysql django django-commands