SQLAlchemy won't update my database

前端 未结 1 1602

I\'m making a Pyramid app using SQLAlchemy-0.7.8. I\'m using 64bit Python3.2.

The question is, why does the following function not commit anything to the database?

相关标签:
1条回答
  • 2020-12-31 10:39

    You need to commit your transaction.

    You can do this explicitly (by calling DBSession.commit() or by using the pyramid_tm middleware; the latter commits transactions automatically on successful responses (with a 2xx HTTP response).

    The latter only commits transactions for SQLAlchemy if you use the ZopeTransactionExtension extension with your session maker:

    from zope.sqlalchemy import ZopeTransactionExtension
    
    DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
    

    If you are already using the ZopeTransactionExtension and want to explicitly commit your transactions, you need to use the transaction package: import transaction

    transaction.commit()
    
    0 讨论(0)
提交回复
热议问题