sqlalchemy session的一个bug

症状: 一样的代码, 在Windows下不能执行数据库操作(Insert...), 但Linux表现正常.

由来:
在sqlalchemy中, 有两种方式创建session.
方法一:

  1. from sqlalchemy.orm import sessionmaker

  2. #创建一个Session对象, 如果有engine:
  3. Session = sessionmaker(bind=engine)
  4. #如果没有engine
  5. Session = sessionmaker()
  6. Session.configure(bind=engine)

  7. #最后实例化session
  8. session = Session()
方法二:
  1. #engine先创建了
  2. engine = create_engine('mysql://root:xxx@localhost/test')
  3. #直接创建session
  4. session = create_session()
我的环境:
Windows:  python 2.5.
Debian: python 2.4.
均为最新版本的sqlalchemy.



通过实验, 我发现在Windows下, 以方式一创建的session不能执行数据库的写操作, 如Insert. 读操作是可以的.
Debian下, 两种方式均可.

解决方法:
不清楚是使用的问题还是环境问题.
或者是框架的问题.
只能使用方法二.


---后记---
使用Session =sessionmaker(bind=engine) 在windows下依然不能insert.    //8.27


你可能感兴趣的:(mysql,linux,windows,数据库,python,session)