Python SQLAlchemy: AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema'

只谈情不闲聊 提交于 2019-11-28 09:52:39

The table definition should be:

friendships = Table('friendships',
                    Base.metadata,
                    Column('follower_id', Integer(), ForeignKey('user.id')),
                    Column('followed_id', Integer(), ForeignKey('user.id'))
)

When defining tables using the declarative syntax, the metadata is inherited through the class declaration from Base, i.e.

Base = declarative_base()

class ChatLog(Base)

but, when defining tables using the old Table syntax, the metadata must be explicitly specified.

I had the same error because I spelled Column with a lowercase c. It should be Column.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!