Hi Zeroth,

I'm sorry for missing that information.
Yes, I'm using MySQL 5.0.x and your question made me check. Turns out
that mysql was creating MyISAM tables for me when I do syncdb with my
models. I've added the following line to my settings.py

DATABASE_OPTIONS = {"init_command": "SET storage_engine=INNODB"}

as found on http://risottoinc.blogspot.com/2007/06/django-mysql-innodb.html,
dropped the whole database and and re-syncd again. It works like a
charm now.

Thank you!

On Nov 30, 1:59 pm, Zeroth <[EMAIL PROTECTED]> wrote:
> Are you using a mysql database? That may be the source of the trouble.
> IIRC, some versions of MySQL, depending on the inner database, don't
> support transactions.
>
> -Zeroth
>
> On Nov 29, 6:56 pm, "I.A" <[EMAIL PROTECTED]> wrote:
>
> > hi guys,
>
> > i'm wondering how transaction really works with django models. i've
> > gone through the documentation 
> > inhttp://docs.djangoproject.com/en/dev/topics/db/transactions/?from=old...
> > but it doesn't work for me.
>
> > this is a sample of my code. not that this code is being used in the
> > backend and does not have any relationship to any views.
>
> > model relationships
> > -------------------------------
>
> > class A(models.Model):
> >    login = models.EmailField(unique=True)
>
> > class B(models.Model):
> >    aid = models.OneToOneField(A, primary_key=True)
> >    colb = models.CharField(max_length=255)
>
> > class C(models.Model):
> >    aid = models.OneToOneField(A, primary_key=True)
> >    colc = models.CharField(max_length=255)
>
> > code
> > ----------------
>
> > class AClass(object):
> >   def register(cls, **kwargs):
> >       try:
> >           a_db = A(login=kwargs['login'])
> >           a_db.save()
> >           function_test_01()
> >           return a_db
> >       except:
> >           raise MyException
>
> > class BClass(AClass):
> >   def register(cls, **kwargs):
> >       try:
> >           a_db =  super(BClass, cls).register(**kwargs)
> >           b_db = B(aid=a_db, colb=kwargs['colb'])
> >           b_db.save()
> >           function_test_02()
> >           return a_db
> >       exception:
> >           raise MyException
>
> > class CClass(BClass):
>
> >   [EMAIL PROTECTED]
> >    def register(cls, **kwargs):
> >       try:
> >           a_db = super(CClass, cls).register(**kwargs)
> >           c_db = C(aid=a_db, colc=kwargs['colc'])
> >           c_db.save()
> >           transaction.commit()
> >       except:
> >           transaction.rollback()
>
> > if __name__ == '__main__':
> >     # Test if register works
> >     CClass.register( colc='abc', colb='def')
>
> > If I run the above script no errors prop up, all three tables will be
> > populated with the data and everything is ok. On the other hand, if
> > something goes wrong in the middle somehwhere, my transaction doesn't
> > work the way i wanted it to.
>
> > For example, when running the test, function_test_02() raises an
> > exception and this is caught by CClass.register()'s except and
> > transaction.rollback() is supposed to be called, but the data in
> > AClass register() was entered into the db. As a result, I have a
> > situation where the only data inserted into the db is A while B and C
> > was not.
>
> > Can anyone point out where I'm doing it wrong?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to