Hi all!
The issue was not from Django side, but really from my models implementation.
I made mistake when propagating my associative tables through other tables. And there was another unity constraint blocking the one i wanted to set.
I don't think it's necessary to explain you all here, because it's purely model issue, not django models issue.
But I fixed the problem.
Thanks anyway for eading.
2012/5/28 Eugene NGONTANG <sympavali@gmail.com>
I encountered a problem using Django foreign key unique_together for
one of my models.
I have three models (representing three tables in the database), host,
user, and job.
- user has a host foreign key
- job has a user foreign key and a host foreign key : Because we can
have the same user on two different host, and the same job for the
users. But we can't (should not) have the same job name duplicate for
the same user and host id.
I use this in my class model :
class Meta:
unique_together = ("job_name", "user", "host")
It works for "./manage.py sqall my_app", and "./manage.py syncdb"
Things go fine untill i try to create a job with the same name in the
admin interface for two different users on the same host.
The django admin accept the request, but it blocks at the sql level,
and returns this execption in the error page:
Exception Value: (1062, "Duplicate entry 'my_command-5' for key
'job_name'")
I can't use this :
class Meta:
unique_together = (("job_name", "user"), ("user",
"host")).
It will be take as to two unique_together case.
That's what the "./manage.py sqall my_app" has generated in the
standard output:
......
UNIQUE (`job_name`, `user_id`, `host_id`)
.....
But how to tell django to tell the sgbd that unicité is to be applied
on the job_name, the user_id and the host_id?
Has anyone encontered this issue?
Thanks for looking.
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
--
ngonta_e@epitech.net
------------------------------------------------------------
Aux hommes il faut un chef, et au chef il faut des hommes!
L'habit ne fait pas le moine, mais lorsqu'on te voit on te juge!
L'habit ne fait pas le moine, mais lorsqu'on te voit on te juge!
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment