Code replicating the error:
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()
Running this code yields:
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)
I'm 95% positive that the filename isn't the issue as I can connect to it from the shell
any ideas?
The return value from sessionmaker()
is a class. You need to instantiate it before using methods on the instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With