python - sqlalchemy: migrate data from mysql to sqlite failes, Index "ClassName" already exists -
i try create local sqlite "working" copy of live mysql database better performance.
i got type conversion mysql->sqlite types working, migration fails during index creation following exception:
sqlalchemy.exc.operationalerror: (sqlite3.operationalerror) index classname exists [sql: u'create index "classname" on "member" ("classname")']
where "classname" column name. full output of engine can found here: http://pastebin.com/zpuqikvs
i think problem same index name reused, don't know how change this.
i use following script:
# -*- coding: utf-8 -*- import os, sys import sqlalchemy sa sqlalchemy.ext.compiler import compiles sqlalchemy.dialects.mysql import enum, mediumtext, tinyint # define mysql -> sqlite mappings @compiles(enum, 'sqlite') def compile_enum(element, compiler, **kw): """ handles mysql enum type string in sqlite""" return compiler.visit_string(element, **kw) # define mysql -> sqlite mappings @compiles(mediumtext, 'sqlite') def compile_mediumtext(element, compiler, **kw): """ handles mysql mediumtext type string in sqlite""" return compiler.visit_string(element, **kw) # define mysql -> sqlite mappings @compiles(tinyint, 'sqlite') def compile_tinyint(element, compiler, **kw): """ handles mysql tinyint type string in sqlite""" return compiler.visit_integer(element, **kw) if __name__ == '__main__': # fix import pwd = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) sys.path.append(pwd) import legacy_config cfg src = sa.create_engine(cfg.sqlalchemy_database_uri) dst = sa.create_engine('sqlite://', echo=true) # create meta , reflect source db meta = sa.metadata() meta.reflect(bind=src) meta.create_all(bind=dst)
Comments
Post a Comment