我在 sqlalchemy 中提交对 pickle 类型(列表)的更改时遇到问题。提交后它将表现得好像什么也没发生一样。
这是我尝试提交的功能:
def commit_move(game_id, player, move):
game = game_query(game_id)
if player == 'human':
game.human_spaces.append(move)
if player == 'ai':
game.ai_spaces.append(move)
game.available_spaces.remove(move)
print game.human_spaces
print game.ai_spaces
print game.available_spaces
print "----"
session.add(game)
session.commit()
该表的设置方式如下:
class Game(Base):
__tablename__ = 'game'
id = Column(Integer, primary_key=True)
human_spaces = Column(PickleType)
ai_spaces = Column(PickleType)
available_spaces = Column(PickleType)
这是我用来测试它的代码:
game_id = create_game()
print game_id
print get_available_spaces(game_id)
print get_human_spaces(game_id)
print get_ai_spaces(game_id)
print "---------"
commit_move(game_id, 'human', 7)
print get_available_spaces(game_id)
print get_human_spaces(game_id)
print get_ai_spaces(game_id)
这就是老终端告诉我的内容:
1
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[]
[]
---------
[7]
[]
[1, 2, 3, 4, 5, 6, 8, 9]
----
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[]
[]
我确信我在这里缺少一些简单的东西,但任何帮助将不胜感激!