邓淳远、崔鹏宇、翁思扬组云计算期末项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
857 B

4 years ago
4 years ago
4 years ago
  1. from sqlalchemy import create_engine
  2. from sqlalchemy.orm import scoped_session, sessionmaker
  3. from sqlalchemy.ext.declarative import declarative_base
  4. engine = create_engine('mysql+pymysql://root:root@mysql:3306/cp', convert_unicode=True)
  5. db_session = scoped_session(sessionmaker(autocommit=False,
  6. autoflush=False,
  7. bind=engine))
  8. Base = declarative_base()
  9. Base.query = db_session.query_property()
  10. def init_db():
  11. # 在这里导入定义模型所需要的所有模块,这样它们就会正确的注册在
  12. # 元数据上。否则你就必须在调用 init_db() 之前导入它们。
  13. import APP.view.model
  14. #file=open('./1.txt','w')
  15. #print('aaaa',file=file)
  16. Base.metadata.drop_all(bind=engine)
  17. Base.metadata.create_all(bind=engine)
  18. #file.close()