python之数据库表迁移
Posted 知_行
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python之数据库表迁移相关的知识,希望对你有一定的参考价值。
1 #!/usr/local/bin/python3.5 2 #coding:utf-8 3 import pymysql 4 import datetime 5 Host = ‘xxxxxxxx‘ 6 User = ‘xxxxxx‘ 7 Pass = ‘xxxxxx‘ 8 Db = ‘xxxxxxx‘ 9 10 db = pymysql.connect(Host, User, Pass, Db) 11 cursor = db.cursor() 12 sql = ‘‘‘ 13 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 14 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx15 16 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 17 18 19 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx21 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; 22 23 ‘‘‘ 24 try: 25 starttime = datetime.datetime.now() 26 cursor.execute(sql) 27 db.commit() 28 endtime = datetime.datetime.now() 29 print(u"执行成功......\n共运行:", (endtime - starttime).seconds, ‘s‘) 30 except Exception as e: 31 print(e) 32 db.rollback() 33 34 db.close()
END !
以上是关于python之数据库表迁移的主要内容,如果未能解决你的问题,请参考以下文章
[python][django学习篇][4]django完成数据库代码翻译:迁移数据库(migration)