Skip to content

Instantly share code, notes, and snippets.

@nklamann
Created March 29, 2023 10:21
Show Gist options
  • Save nklamann/6f37d8a02f94281ebd80e4e6b6ea4cf5 to your computer and use it in GitHub Desktop.
Save nklamann/6f37d8a02f94281ebd80e4e6b6ea4cf5 to your computer and use it in GitHub Desktop.
Trying to transfer columns from Oracle to SQLite via SQLAlchemy, related to https://github.com/sqlalchemy/sqlalchemy/discussions/9558
Traceback (most recent call last):
File "c:\projects\md2\src\testcase.py", line 28, in <module>
sqll_table.create(sqlite_engine)
File "C:\projects\md2\venv\Lib\site-packages\sqlalchemy\sql\schema.py", line 1149, in create
bind._run_ddl_visitor(ddl.SchemaGenerator, self, checkfirst=checkfirst)
File "C:\projects\md2\venv\Lib\site-packages\sqlalchemy\engine\base.py", line 3226, in _run_ddl_visitor
conn._run_ddl_visitor(visitorcallable, element, **kwargs)
File "C:\projects\md2\venv\Lib\site-packages\sqlalchemy\engine\base.py", line 2430, in _run_ddl_visitor
visitorcallable(self.dialect, self, **kwargs).traverse_single(element)
File "C:\projects\md2\venv\Lib\site-packages\sqlalchemy\sql\visitors.py", line 670, in traverse_single
return meth(obj, **kw)
^^^^^^^^^^^^^^^
File "C:\projects\md2\venv\Lib\site-packages\sqlalchemy\sql\ddl.py", line 951, in visit_table
if column.default is not None:
^^^^^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'default'. Did you mean: 'setdefault'?
DIALECT = "oracle"
SQL_DRIVER = "oracledb"
USERNAME = "xxxxxx" # enter your username
PASSWORD = "xxxxxx" # enter your password
TNSNAME = "RMANTDB2"
ENGINE_PATH_WIN_AUTH = (
DIALECT + "+" + SQL_DRIVER + "://" + USERNAME + ":" + PASSWORD + "@" + TNSNAME
)
from sqlalchemy import create_engine, MetaData, inspect, Table
ora_engine = create_engine(
ENGINE_PATH_WIN_AUTH,
thick_mode={
"lib_dir": r"C:\opt\instantclient_21_9",
"config_dir": r"C:\etc\oracle",
},
)
ora_md = MetaData(schema="BETRIEB")
insp = inspect(ora_engine)
cols_in_source = insp.get_columns("meta_object_columns", schema="BETRIEB")
# some columns might be deleted, some might be added
sqlite_engine = create_engine("sqlite://")
sqll_md = MetaData()
sqll_md.reflect(bind=sqlite_engine)
sqll_table = Table("meta_object_columns", sqll_md)
# same columns as original , just for test
sqll_table.columns=cols_in_source
sqll_table.create(sqlite_engine)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment