Following is my file having all Table mapper classes.
// import statements
Class MyBase(AbstractBase, Base):
session = None
def __init__(self):
global Session
self.session = Session()
// init statements
Class Table1(MyBase):
// fields
engine = create_engine("...")
Session = session_maker(engine)
Base = declarative_base()
Base.meta.create_all()
I am getting
NameError: name 'Base' is not defined
since my class is extending it beforeBase
initialization.I can make it work, if I move engine creation, Session creation & Base creation above defining classes. But
Base.meta.create_all()
should be present below the class declaration. If I placeBase.meta.create_all()
above classes, there is no table created.I do not want to have the
main()
because, I am basically going to import this file in some other file.
So, I want to keep all statements(engine, session, base & create_all()) after the class definitions.
Aucun commentaire:
Enregistrer un commentaire