代码复制错误:
from sqlalchemy import create_engine, Table, Column, Integer
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
Base = declarative_base()
class Message(Base):
__tablename__ = 'messages'
id = Column(Integer, primary_key=True)
message = Column(Integer)
engine = create_engine('sqlite:///' + filename_of_your_choice)
session = sessionmaker(bind=engine)
newmessage = Message()
newmessage.message = "Hello"
messages = session.query(Message).all()
运行此代码会产生:
Traceback (most recent call last):
File "C:/aaron/test.py", line 20, in <module>
session.commit()
TypeError: unbound method commit() must be called with Session instance as first argument (got nothing instead)
我95%肯定文件名不是问题,因为我可以从shell连接到它
任何想法?