sqlalchemy existing database code example
Example: sqlalchemy existing db file
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
from sqlalchemy import create_engine
Base = automap_base()
engine = create_engine("sqlite:///mydatabase.db")
Base.prepare(engine, reflect=True)
User = Base.classes.user
Address = Base.classes.address
session = Session(engine)
session.add(Address(email_address="[email protected]", user=User(name="foo")))
session.commit()
print (u1.address_collection)