0

I already have an engine defined for my postgres database. I want to create a new engine using sqlite and use what existing classes I already have.

I have it set up like this for postgres:

conn_url = '<connection_string>'
engine = create_engine(conn_url, echo=False)
Session = sessionmaker(bind=engine)
Base = declarative_base()


class SomeTable(Base):
    __tablename__ = 'some_table'
    id = Column(Integer, primary_key=True, autoincrement=True)
    some_field = Column(String(100))

How do I use SomeTable with an sqlite engine like this engine = create_engine('sqlite:///')?

1 Answer 1

1

All I had to do was

import SomeTable from models

engine = create_engine('sqlite:///')
SomeTable.metadata.create_all(engine)

I thought I'd have to do that for every model that I have, but it works just fine using any model.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.