【发布时间】:2020-06-26 06:24:35
【问题描述】:
我正在尝试从 Redshift 数据库中获取表的元数据。 即使连接正常,我也会收到错误消息。 "TypeError: _get_column_info() 得到了一个意外的关键字参数 'generated'"
我尝试使用不同服务器的另一个数据库,它工作正常...... 但不确定此服务器表有什么问题。 你能帮我解决一下吗?
Table=sa.Table("Tablename" ,metadata,autoload=True,autoload_with=engine)
TypeError Traceback (most recent call last)
<ipython-input-98-366ec112cf52> in <module>
----> 1 Table=sa.Table("dim_dealer" ,metadata,autoload=True,autoload_with=engine)
<string> in __new__(cls, *args, **kw)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sqlalchemy\util\deprecations.py in warned(fn, *args, **kwargs)
126 )
127
--> 128 return fn(*args, **kwargs)
129
130 doc = fn.__doc__ is not None and fn.__doc__ or ""
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sqlalchemy\sql\schema.py in __new__(cls, *args, **kw)
494 except:
495 with util.safe_reraise():
--> 496 metadata._remove_table(name, schema)
497
498 @property
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sqlalchemy\util\langhelpers.py in __exit__(self, type_, value, traceback)
66 self._exc_info = None # remove potential circular references
67 if not self.warn_only:
---> 68 compat.reraise(exc_type, exc_value, exc_tb)
69 else:
70 if not compat.py3k and self._exc_info and self._exc_info[1]:
~\AppData\Local\Continuum\anaconda3\lib\`enter code here`site-packages\sqlalchemy\util\compat.py in reraise(tp, value, tb, cause)
151 if value.__traceback__ is not tb:
152 raise value.with_traceback(tb)
--> 153 raise value
154
155 def u(s):
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sqlalchemy\sql\schema.py in __new__(cls, *args, **kw)
489 metadata._add_table(name, schema, table)
490 try:
--> 491 table._init(name, metadata, *args, **kw)
492 table.dispatch.after_parent_attach(table, metadata)
493 return table
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sqlalchemy\sql\schema.py in _init(self, name, metadata, *args, **kwargs)
583 include_columns,
584 _extend_on=_extend_on,
--> 585 resolve_fks=resolve_fks,
586 )
587
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sqlalchemy\sql\schema.py in _autoload(self, metadata, autoload_with, include_columns, exclude_columns, resolve_fks, _extend_on)
607 exclude_columns,
608 resolve_fks,
--> 609 _extend_on=_extend_on,
610 )
611 else:
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sqlalchemy\engine\base.py in run_callable(self, callable_, *args, **kwargs)
2148 """
2149 with self._contextual_connect() as conn:
-> 2150 return conn.run_callable(callable_, *args, **kwargs)
2151
2152 def execute(self, statement, *multiparams, **params):
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sqlalchemy\engine\base.py in run_callable(self, callable_, *args, **kwargs)
1602
1603 """
-> 1604 return callable_(self, *args, **kwargs)
1605
1606 def _run_visitor(self, visitorcallable, element, **kwargs):
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sqlalchemy\engine\default.py in reflecttable(self, connection, table, include_columns, exclude_columns, resolve_fks, **opts)
429 insp = reflection.Inspector.from_engine(connection)
430 return insp.reflecttable(
--> 431 table, include_columns, exclude_columns, resolve_fks, **opts
432 )
433
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sqlalchemy\engine\reflection.py in reflecttable(self, table, include_columns, exclude_columns, resolve_fks, _extend_on)
638
639 for col_d in self.get_columns(
--> 640 table_name, schema, **table.dialect_kwargs
641 ):
642 found_table = True
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sqlalchemy\engine\reflection.py in get_columns(self, table_name, schema, **kw)
371
372 col_defs = self.dialect.get_columns(
--> 373 self.bind, table_name, schema, info_cache=self.info_cache, **kw
374 )
375 for col_def in col_defs:
<string> in get_columns(self, connection, table_name, schema, **kw)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sqlalchemy\engine\reflection.py in cache(fn, self, con, *args, **kw)
54 ret = info_cache.get(key)
55 if ret is None:
---> 56 ret = fn(self, con, *args, **kw)
57 info_cache[key] = ret
58 return ret
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sqlalchemy_redshift\dialect.py in get_columns(self, connection, table_name, schema, **kw)
459 default=col.default, notnull=col.notnull, domains=domains,
460 enums=[], schema=col.schema, encode=col.encode,
--> 461 comment=col.comment)
462 columns.append(column_info)
463 return columns
~\AppData\Local\Continuum\anaconda3\lib\site-packages\sqlalchemy_redshift\dialect.py in _get_column_info(self, *args, **kwargs)
666 column_info = super(RedshiftDialect, self)._get_column_info(
667 *args,
--> 668 **kw
669 )
670 if isinstance(column_info['type'], VARCHAR):
TypeError: _get_column_info() got an unexpected keyword argument 'generated'
print(repr(metadata.tables[Table]))
提前致谢
【问题讨论】:
-
您能在帖子中添加
sqlalchemy和sqlalchemy-redshift软件包的版本吗? -
@SergeyShubin 包的版本是 sqlalchemy : 1.3.7 sqlalchemy-redshift: 0.7.9
标签: python sqlalchemy amazon-redshift metadata