AttributeError: module 'sqlalchemy.orm' has no attribute 'DeclarativeMeta'
时间: 2023-09-23 07:11:34 浏览: 119
AttributeError: module 'tensorflow.compat.v1' has no attribute '
This error occurs when you are trying to use the `DeclarativeMeta` class from the `sqlalchemy.orm` module, but it is not defined in that module.
To fix this error, you can try importing the `declarative_base` function from the `sqlalchemy.ext.declarative` module instead. Here's an example:
```
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
```
Then you can define your ORM classes using `Base` as the base class:
```
from sqlalchemy import Column, Integer, String
class MyTable(Base):
__tablename__ = 'my_table'
id = Column(Integer, primary_key=True)
name = Column(String)
...
```
This should resolve the `AttributeError` and allow you to use the `declarative_base` function to define your ORM classes.
阅读全文