1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Getting SQLAlchemy to issue CREATE SCHEMA on create_all

Discussão em 'Python' iniciado por Stack, Novembro 24, 2025.

  1. Stack

    Stack Membro Participativo

    I have a SqlAlchemy model with a schema argument like so:

    Base = declarative_base()

    class Road(Base):
    __tablename__ = "roads"
    __table_args__ = {'schema': 'my_schema'}
    id = Column(Integer, primary_key=True)


    When I use Base.metadata.create_all(engine) it correctly issues a CREATE TABLE with the schema name on the front like so CREATE TABLE my_schema.roads ( but Postgresql rightly complains that the schema doesn't exist.

    Am I missing a step to get SqlAlchemy to issue the CREATE SCHEMA my_schema or do I have to call this manually?

    Continue reading...

Compartilhe esta Página