سؤال

I have the following ORM mapping using SqlAlchemy:

class Foo(Base):
    __tablename__ = "foo"
    id = Column(Integer, primary_key=True)
    name = Column(String)
    date_imported = Column(DateTime)

However, how can I either get the CREATE TABLE sql syntax or how I can I have it create the table for me?

هل كانت مفيدة؟

المحلول

Use Foo.__table__.create(bind=engine, checkfirst=True) to issue the statement for that table, or metadata.create_all(bind=engine) to issue the statements for all tables registered on that metadata. If you are using Flask-SQLAlchemy, use db.create_all() to honor binds correctly.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top