Setting schema in Oracle or Postgresql

linkaiyi
Follow

setting schema in model definition

  1. define schema in each table:
SCHEMA = {'schema': 'emob'}

class Customer(Base):
    __tablename__ = 'customer'
    __table_args__ = SCHEMA
  1. define MetaData object for Base:
from sqlalchemy import MetaData


Base = sqlalchemy.ext.declarative.declarative_base()
Base.metadata = MetaData(schema='emob')

class Customer(Base):

All above 2 cases, the foreign key should contain schema name.

customer_id = sqlalchemy.Column('customer_id', BigInteger, ForeignKey('emob.customer.id', ondelete="SET NULL"), nullable=True)
  1. if the connection to oracle has a default schema, none of above should be applied. Otherweise alembic will be confused with schema names
Object has 0 attachments

Was this article helpful?

This article is viewed 48 times!

0 Comments

Leave a Comment

Support