AttributeError while querying: Neither 'InstrumentedAttribute' object nor 'Comparator' has an attribute

前端 未结 4 1341
旧巷少年郎
旧巷少年郎 2021-01-31 14:33

The following code:

Base = declarative_base()
engine = create_engine(r\"sqlite:///\" + r\"d:\\foo.db\",
                       listeners=[ForeignKeysListener()])         


        
4条回答
  •  后悔当初
    2021-01-31 14:49

    A related error that can be caused by configuring your SQLAlchemy relationships incorrectly:

    AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'corresponding_column'
    

    In my case, I incorrectly defined a relationship like this:

    namespace   = relationship(PgNamespace, id_namespace, backref="classes")
    

    The id_namespace argument to relationship() should just not be there at all. SQLAlchemy is trying to interpret it as an argument of a different type, and failing with an inscrutable error.

提交回复
热议问题