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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment