Hi everybody,

I am experiencing the same issue commented 
here: 
https://bitbucket.org/zzzeek/alembic/issues/293/alembic-autogenerate-creates-endless

In my case, I have the model:
-----------8<--------------
...
class EmailAttachment(Base):
    __tablename__ = 'email_attachment'
    __table_args__ = table_args

email_message_id = Column(ForeignKey(EmailMessage.id), nullable=False)
filestorage_file_id = Column(Integer, nullable=False)

email_message = relationship(EmailMessage, backref='email_attachments')

def __init__(self, email_message_id=None, email_message=None,
filestorage_file_id=None, fxt=None):
self.email_message_id = email_message_id
self.email_message = email_message
self.filestorage_file_id = filestorage_file_id
self.fxt = fxt
...
-----------8<--------------

Where:
-----------8<--------------
...
table_args = {'schema': 'notifications'}

class NotificationsBase:
    @declared_attr
    def id(cls):
        return Column(Integer, primary_key=True)

    @declared_attr
    def fxt(cls):
        return Column(String, nullable=True)

    @classmethod
    def get_one(cls, **kwargs):
        query = DBSession.query(cls)
        for k, v in kwargs.items():
            query = query.filter(getattr(cls, k) == v)
        return query.one()

    def __repr__(self):
        return "<%s id=%s>" % (self.__class__.__name__, self.id)


Base = declarative_base(cls=NotificationsBase)
...
-----------8<--------------


Running 'alembic -c development.ini revision -m "upgrade" --autogenerate' 
without any change to the model, alembic insists on dropping the foreign 
key and recreating it afterwards. It is happening to all the foreign keys 
of all the models of the project. The generated script looks like:
-----------8<--------------
...
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint('email_attachment_email_message_id_fkey', 
'email_attachment', type_='foreignkey')
    op.create_foreign_key(None, 'email_attachment', 'email_message', 
['email_message_id'], ['id'], source_schema='notifications', 
referent_schema='notifications')
...
-----------8<--------------

For more information, my env.py has:
-----------8<--------------
...

target_metadata = Base.metadata

def include_symbol(tablename, schema):
    return schema == table_args['schema']

...

def run_migrations_online():

    connection = engine.connect()
    context.configure(
        connection=connection,
        target_metadata=target_metadata,
        include_schemas=True,
        include_symbol=include_symbol,
        version_table_schema='public'
    )

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()

if context.is_offline_mode():
    run_migrations_offline()
else:
    run_migrations_online()
-----------8<--------------

And all this with SQLAlchemy 1.0.8, Alembic 0.8.2 and PostgreSQL 9.3.7. Any 
clue of what could be the source of the problem?

Cheers,
Sergi



-- 
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