Sqlalchemy if table does not exist

后端 未结 4 722
南方客
南方客 2021-01-31 14:28

I wrote a module which is to create an empty database file

def create_database():
    engine = create_engine(\"sqlite:///myexample.db\", echo=True)
    metadata          


        
4条回答
  •  南旧
    南旧 (楼主)
    2021-01-31 15:05

    Note that in 'Base.metadata' documentation it states about create_all:

    Conditional by default, will not attempt to recreate tables already present in the target database.

    And if you can see that create_all takes these arguments: create_all(self, bind=None, tables=None, checkfirst=True), and according to documentation:

    Defaults to True, don't issue CREATEs for tables already present in the target database.

    So if I understand your question correctly, you can just skip the condition.

提交回复
热议问题