On Apr 16, 8:33 am, limas <limasathyanan...@gmail.com> wrote:
> I were using Mysql MyISAM. But I want to enable transaction.
> So i shifted to InnoDB.
> Actually I have one model as below (*designed somebody i can't
> change).
>
> class Folder(models.Model):
>         folder_id=models.AutoField(primary_key=True)
>         user_name=models.ForeignKey(User)
>         folder_name=models.CharField(max_length=80)
>         parent_folder=models.ForeignKey('self')
>
> At some point i want to insert in this table as below:
> Folder(user_name_id=1,folder_name="s",parent_folder_id=0)
>
> But it raises one error like this.
>
> IntegrityError: (1452, 'Cannot add or update a child row: a foreign
> key constraint fails (`myproject/folder_folder`, CONSTRAINT
> `parent_folder_id_refs_folder_id_12515019` FOREIGN KEY
> (`parent_folder_id`) REFERENCES `folder_folder` (`folder_id`))')
>
> But with MyISAM there was no problem like this.......
>
> Anyways i need Transaction functionality for other tables in the
> database.
> Is there any solution for this problem. Please Help me.
>
> Thanks
> Lima

The other difference between InnoDB and MyISAM is that InnoDB supports
- and enforces - foreign key constraints. '0' does not refer to an
existing folder_id, so the constraint fails. There isn't any way
around that with the way you've set up your models currently: you need
to change the parent_folder field so that null=True.

You say you can't change the db structure, but obviously you've
already made some changes to it to move to InnoDB. I recommend you add
null=True to the Django field definition, then run this SQL on the
database:
ALTER TABLE appname_folder MODIFY COLUMN parent_folder_id INTEGER
NULL;

Now you can define your folder without setting a parent_folder:
Folder(user_name_id=1,folder_name="s")

--
DR.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to