Код: Выделить всё
def init_model(engine):
"""Call me before using any of the tables or classes in the model"""
t_events = Table('events', Base.metadata, schema='events', autoload=True, autoload_with=engine)
orm.mapper(Event, t_events)
Session.configure(bind=engine)
class Event(object):
pass
Код: Выделить всё
class Event(Base):
__tablename__ = 'events'
__table_args__ = {'schema': 'events', 'autoload': True}
sqlalchemy.exc.UnboundExecutionError: Ни один механизм не привязан к метаданным этой таблицы. Передайте механизм в таблицу с помощью autoload_with= или свяжите метаданные с механизмом с помощью Metadata.bind=
Проблема здесь в том, что я не знаю, откуда взять движок (чтобы использовать его в autoload_with) на этапе импорта модели (он доступен в init_model()). Я попробовал добавить
Код: Выделить всё
meta.Base.metadata.bind(engine)
Подробнее здесь: https://stackoverflow.com/questions/452 ... -in-pylons