Migrated issue, originally created by dataradiant ()
I have a foreign key where the remote column is referenced by name and link_to_name=True. When using autogenerate, I receive a KeyError on the column name here: https://bitbucket.org/zzzeek/alembic/src/feaea56b97a11f4f132fb5f55d8a6b71dc0b9c04/alembic/autogenerate/render.py?at=master&fileviewer=file-view-default#render.py-685
It's trying to lookup the column using the string provided, which in this case is the name rather than the key, which obviously doesn't work so well when they aren't the same.
Replacing that line with a conditional that checks for link_to_name seems to work at least for my case:
if fk.link_to_name:
colname = _ident(colname)
else:
colname = _ident(parent_metadata.tables[table_fullname].c[colname].name)
该提问来源于开源项目:sqlalchemy/alembic