setting schema in model definition
- define schema in each table:
SCHEMA = {'schema': 'emob'}
class Customer(Base):
__tablename__ = 'customer'
__table_args__ = SCHEMA
- 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)
- if the connection to oracle has a default schema, none of above should be applied. Otherweise alembic will be confused with schema names