擅长:python、mysql、java
<p>在您的<code>UserPermission</code>类中,您使用了错误的dunder属性:</p>
<pre><code>__table__ = 'userPermissions'
</code></pre>
<p>应该是:</p>
^{pr2}$
<p>Sqlalchemy正在尝试将字符串<code>'userPermissions'</code>视为<code>Table</code>对象。在</p>
<p>关于<code>__table__</code>和<code>__tablename__</code>之间的区别,大多数情况下只需要在声明类上声明{<cd6>}。它表示对象应该引用该名称的表,SQLAlchemy可以在内部处理<code>Table</code>对象的构造。在</p>
<p>在对象上声明一个<code>__table__</code>,而是向SQLAlchemy发出信号,表示您想要控制ORM类所表示的<code>Table</code>的构造。如果您已经通过其他方式(如表反射)引用了表,那么这将非常有用。更多阅读<a href="https://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/table_config.html?highlight=__table__#using-a-hybrid-approach-with-table" rel="nofollow noreferrer">here</a>。在</p>