sqlalchemy.exc.StatementError:(builtins.TypeError)memoryview:需要一个类似字节的对象,而不是'str'

时间:2017-02-20 05:09:13

标签: python sqlalchemy

我正在尝试使用python和SQLAlchemy ORM在sqlite数据库中存储对象。 以下是我的代码
存储到sqlite db的代码段

command='some command'# a str variable  containing some value
length = len(command) # length of string 
mycommand = Command(command, length, 0, 'nothing') # instantiating object
Session.add(mycommand )
Session.commit()

用于创建会话对象的代码段

engine = create_engine('sqlite:///commands.db', convert_unicode=True)
Session = sessionmaker(bind=engine)()

现在,当我尝试使用session.add(obj)将新的crated对象持久化到sqlite db时,我收到一个错误: sqlalchemy.exc.StatementError:(builtins.TypeError)memoryview:需要类似字节的对象,

我已正确创建Command类并将其属性映射到命令表中的相应列。 我该如何解决这个错误?

0 个答案:

没有答案