all three of your files do: from database import Base
so that is just one Base object, one metadata object. they are all the same. if you wanted them separate you'd need to call upon "Base = declarative_base()" in each module individually. On Sat, Mar 24, 2018 at 1:11 PM, <jackadam1...@gmail.com> wrote: > myproject just like this: > > ├─migrate > > │ ├─versions > > │ │ └─94d0834e4282_.py > > │ │ └─__pycache__ > > │ └─evn.py > > │ └─README > > │ └─evn.py > > │ └─cript.py.mako > > ├─models > │ └─test1.py > > │ └─test2.py > > │ └─test3.py > > ├─__pycache__ > > ├─alembic.ini > > ├─database.py > > └─main.py > > > database.py: > > from sqlalchemy import create_engine > from sqlalchemy.orm import scoped_session, sessionmaker > from sqlalchemy.ext.declarative import declarative_base > > engine = create_engine('mysql+mysqlconnector://plan:plan@mysql/test', > convert_unicode=True) > db_session = scoped_session(sessionmaker(autocommit=False, > autoflush=False, > bind=engine)) > Base = declarative_base() > Base.query = db_session.query_property() > > def init_db(): > # import all modules here that might define models so that > # they will be registered properly on the metadata. Otherwise > # you will have to import them first before calling init_db() > Base.metadata.create_all(bind=engine) > > > #test1.py: > > from sqlalchemy import Column, Integer, String > from database import Base > > class User1(Base): > __tablename__ = 'users1' > id1 = Column(Integer, primary_key=True) > name1 = Column(String(50), unique=True) > email1 = Column(String(120), unique=True) > > def __init__(self, name=None, email=None): > self.name = name > self.email = email > > def __repr__(self): > return '<User %r>' % (self.name1) > > > #test2.py: > > from sqlalchemy import Column, Integer, String > from database import Base > > class User2(Base): > __tablename__ = 'users2' > id1 = Column(Integer, primary_key=True) > name2 = Column(String(50), unique=True) > email2 = Column(String(120), unique=True) > > def __init__(self, name=None, email=None): > self.name = name > self.email = email > > def __repr__(self): > return '<User %r>' % (self.name2) > > > #test3.py > > from sqlalchemy import Column, Integer, String > from database import Base > > class User3(Base): > __tablename__ = 'users3' > id1 = Column(Integer, primary_key=True) > name3 = Column(String(50), unique=True) > email3 = Column(String(120), unique=True) > > def __init__(self, name=None, email=None): > self.name = name > self.email = email > > def __repr__(self): > return '<User %r>' % (self.name3) > > > database.py: > > from sqlalchemy import create_engine > from sqlalchemy.orm import scoped_session, sessionmaker > from sqlalchemy.ext.declarative import declarative_base > > engine = create_engine('mysql+mysqlconnector://plan:plan@mysql/test', > convert_unicode=True) > db_session = scoped_session(sessionmaker(autocommit=False, > autoflush=False, > bind=engine)) > Base = declarative_base() > Base.query = db_session.query_property() > > def init_db(): > # import all modules here that might define models so that > # they will be registered properly on the metadata. Otherwise > # you will have to import them first before calling init_db() > Base.metadata.create_all(bind=engine) > > > > > #database.py just set database url > > sqlalchemy.url = mysql+mysqlconnector://plan:plan@mysql/test > > #alembic.ini just set database url > > sqlalchemy.url = mysql+mysqlconnector://plan:plan@mysql/test > > > #env.py just set target_metadata > > import os > import sys > sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../") > from models import test1,test2,test3 > target_metadata = test1.Base.metadata > > > > this code Autogenerating Multiple MetaData collections all set test2 test3. > > the documentation say: > > Autogenerating Multiple MetaData collections¶ > > Thetarget_metadatacollection may also be defined as a sequenceif an > application has multipleMetaDatacollections involved: > > from myapp.mymodel1 import Model1Base > from myapp.mymodel2 import Model2Base > target_metadata = [Model1Base.metadata, Model2Base.metadata] > > > i can't use env.py\target_metadata like this: > > import os > import sys > sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../") > from models import test1,test2,test3 > target_metadata = > [test1.Base.metadata,test2.Base.metadata,test3.Base.metadata] > > > > i use env.py\target_metadata like this: > > import os > import sys > sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../") > from models import test1,test2,test3 > target_metadata = test1.Base.metadata > > > all build test1 test2 test3. > > > is this bug? > > > sorry for my bad english. > > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy-alembic" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy-alembic+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sqlalchemy-alembic" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy-alembic+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.