开发者

objects.get_or_create() or transactions in Django views

OK, objects.get_or_create(), when called, will create a new record in the database (if there is no record I need). But what if the code throws an exception/fails AFTER objects.get_or_create() has been called?

Basically, I end up with a new record in the database which should not be there. To put it differently, shouldn't 开发者_StackOverflow社区the whole thing be wrapped in a transaction which is rolled back if there is a problem? Is it possible?


As Ignacio suggests the answer (in much greater detail than I would be capable of) is available in the django docs.

http://docs.djangoproject.com/en/dev/topics/db/transactions

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜