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¶ 
<http://alembic.zzzcomputing.com/en/latest/autogenerate.html?highlight=target_metadata#autogenerating-multiple-metadata-collections>

Thetarget_metadatacollection may also be defined as a sequenceif an application 
has multipleMetaData 
<http://docs.sqlalchemy.org/en/latest/core/metadata.html#sqlalchemy.schema.MetaData>collections
 involved:

from myapp.mymodel1 import Model1Basefrom myapp.mymodel2 import 
Model2Basetarget_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.

Reply via email to