Skip to content

Alembic generates redundant foreign key operations for existing cross-schema references in PostgreSQL #1676

Closed Answered by zzzeek
jhamer8 asked this question in Usage Questions
Discussion options

You must be logged in to vote

Hi -

there's a lot of text here but the first thing I see in the code is something that likely needs to change:

class TableA(db.Model):
    __tablename__ = 'table_a'
    __table_args__ = {"schema": "public"}
    
    id = db.Column(db.Integer, primary_key=True)
    table_b_id = db.Column(db.Integer, db.ForeignKey('schema_b.table_b.id'))
    table_c_id = db.Column(db.Integer, db.ForeignKey('public.table_c.id'))

PostgreSQL database defines the default schema search path as essentially "public", meaning the name "public" is known in SQLAlchemy as the default schema. It will get confused if you name this schema explicitly in your models, so you should remove the name "public" here.

See the fo…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jhamer8
Comment options

Answer selected by jhamer8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
requires triage New issue that requires categorization
2 participants
Converted from issue

This discussion was converted from issue #1675 on June 08, 2025 20:22.