Bạn đã tạo Base trong Item.py , chỉ cần nhập nó vào main.py :
Nếu main.py và Item.py nằm trên cùng một thư mục, sau đó nằm trong main.py :
from Item import Base, Item
Và xóa tất cả các mục nhập bên trong main chức năng, vì vậy main.py sẽ giống như sau:
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from Item import Base, Item
def main():
engine = create_engine('postgresql+psycopg2://me:example@sqldat.com/my_first_database', echo=True)
print(Item)
print(Item.__table__)
Base.metadata.create_all(engine)
main()