赞
踩
from sqlalchemy import Column, String, create_engine, Integer, DateTime from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base from datetime import datetime engine = create_engine("sqlite:///test.db") Session = sessionmaker() Session.configure(bind=engine) session = Session() Base= declarative_base(engine) class Test(Base): __tablename__ = 'test' id = Column(Integer, autoincrement=True, primary_key=True) name = Column(String(50)) age = Column(String(50)) create_time = Column(DateTime, default=datetime.now) del_list = [Test.__table__, ] # Base.metadata.drop_all(tables=del_list) Base.metadata.create_all(tables=del_list) item_dict = { 'name': 'lucy', 'age': 20 } item = Test(**item_dict) session.add(item) session.commit()
效果图
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。