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
精彩评论