engine = create_engine("sqlite:///mydatabase.db")
# reflect the tables
- Base.prepare(engine, reflect=True)
+ Base.prepare(autoload_with=engine)
# mapped classes are now created with names by default
# matching that of the table name.
# reflect
engine = create_engine("sqlite:///mydatabase.db")
- Base.prepare(engine, reflect=True)
+ Base.prepare(autoload_with=engine)
# we still have Address generated from the tablename "address",
# but User is the same as Base.classes.User now
engine = create_engine("sqlite:///mydatabase.db")
- Base.prepare(engine, reflect=True,
+ Base.prepare(autoload_with=engine,
classname_for_table=camelize_classname,
name_for_collection_relationship=pluralize_collection
)
Base = automap_base()
engine = create_engine("sqlite:///mydatabase.db")
- Base.prepare(engine, reflect=True,
+ Base.prepare(autoload_with=engine,
generate_relationship=_gen_relationship)
Many-to-Many relationships
return name
- Base.prepare(engine, reflect=True,
+ Base.prepare(autoload_with=engine,
name_for_scalar_relationship=name_for_scalar_relationship)
Alternatively, we can change the name on the column side. The columns
__tablename__ = 'table_b'
_table_a = Column('table_a', ForeignKey('table_a.id'))
- Base.prepare(engine, reflect=True)
+ Base.prepare(autoload_with=engine)
Using Automap with Explicit Declarations
column_info['key'] = "attr_%s" % column_info['name'].lower()
# run reflection
- Base.prepare(engine, reflect=True)
+ Base.prepare(autoload_with=engine)
.. versionadded:: 1.4.0b2 the :meth:`_events.DDLEvents.column_reflect` event
may be applied to a :class:`_schema.MetaData` object.
are present under the name they were given, e.g.::
Base = automap_base()
- Base.prepare(engine=some_engine, reflect=True)
+ Base.prepare(autoload_with=some_engine)
User, Address = Base.classes.User, Base.classes.Address