weixin_39890652 2020-11-30 11:27
浏览 0

Alembic Foreign Keys getting removed and re-added on every new migration

Migrated issue, originally created by Waseem Jan ()

Every time I create a new revision, Alembic tries to remove the already existing foreign keys and then tries to add them again. Logs looks like this


INFO  [alembic.autogenerate.compare] Detected removed foreign key (post_id)(post_id) on table album_photos
INFO  [alembic.autogenerate.compare] Detected removed foreign key (album_id)(album_id) on table album_photos
INFO  [alembic.autogenerate.compare] Detected removed foreign key (user_id)(user_id) on table album_photos
INFO  [alembic.autogenerate.compare] Detected added foreign key (album_id)(album_id) on table prodcat.album_photos
INFO  [alembic.autogenerate.compare] Detected added foreign key (post_id)(post_id) on table prodcat.album_photos
INFO  [alembic.autogenerate.compare] Detected added foreign key (user_id)(user_id) on table prodcat.album_photos

I have tried adding name to each Foreign Key constraint but that doesn't have any effect. My tables reside in multiple Postgresql Schemas and I have hardcoded the schema information in each model class like this


class AlbumPhotos(db.Model, TimeStampMixin, HasLikes, HasComments):
    __tablename__ = 'album_photos'
    __table_args__ = {'schema' : 'prodcat'}
    id = db.Column('photo_id',db.Integer, primary_key=True)

Here is more detail explanation of the problem http://stackoverflow.com/questions/41150956/alembic-not-generating-correct-changes

该提问来源于开源项目:sqlalchemy/alembic

  • 写回答

6条回答 默认 最新

  • weixin_39890652 2020-11-30 11:27
    关注

    Michael Bayer () wrote:

    this is not a bug report, it's a usage question. Your issue is either that your ForeignKeyConstraint definitions (not shown here, so I have no idea) are not specifying the schema correctly, and/or you are not using the correct search path (e.g. "public" and nothing else). one of those two areas is likely where something needs adjustment.

    评论

报告相同问题?