Can you please explain how to define I'd in model.Cascade
On Feb 26, 2019 4:14 AM, "Phako Perez" <13.phakman@gmail.com> wrote:
I guess you need to define first the id in models.CASCADE,
When you try to insert as per your table definition it looks for the key on that tableHope this can be helpfulmanager = models.ForeignKey('self', null=True, related_name='employee',on_delete=models.CASCADE) Happy coding!!!Sent from my iPhone--getting error{"manager":["Invalid pk \"1\" - object does not exist."]}here is my model classclass Employee(models.Model):
MANAGER = 'MGR'
STANDARD = 'STD'
EMPLOYEE_TYPES = (
(MANAGER, 'manager'),
(STANDARD, 'employee')
)
role = models.CharField(max_length=25, choices=EMPLOYEE_TYPES)
name = models.CharField(max_length=100 , null=True, blank=True)
employee_id = models.CharField(max_length=100 , null=True, blank=True)
manager = models.ForeignKey('self', null=True, related_name='employee',on_delete =models.CASCADE)
and json data which i am using to save in table
{
"role":"MGR",
"name":"John",
"employee_id" :"IN",
"manager":1
}
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com .
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users .
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/454e6708- .d6f6-43ee-8542-85d92a69d1cd% 40googlegroups.com
For more options, visit https://groups.google.com/d/optout .
--To view this discussion on the web visit https://groups.google.com/d/
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com .
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users .msgid/django-users/CF0263A3- .5575-4CFF-A778-D2482DD8DB76% 40gmail.com
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJB94UOiEXX_71DzSbhMhN%3DE9H3mwB_oCtPmDiQjDP-gaTPicg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment