class Subscribers(User):
date = models.DateField()
user = models.OneToOneField(User)
class Tour(models.Model):
""" This is not the id is a User object
"""
owner_id = models.ForeignKey(User)
name = models.CharField(max_length=50, primary_key=True)
location = models.ManyToManyField(Location)
subscribers = models.ManyToManyField(Subscribers, related_name="sub")
以下を使用してメソッドをテストしようとしています。
def test_get_subsribers(self):
user1= User.objects.create_user('Maria','j@j.com','j1')
user4= User.objects.create_user('Giannis','m@m.com','m1')
sub= Subscribers()
sub.user = user4
tour = Tour()
tour.owner_id = user1
tour.name = "Open Day"
tour.subscribers.add(sub)
self.assertEqual(get_subscribers("Open Day").count(),0)
しかし、私が得るのはエラーです:
IntegrityError: insert or update on table "tour_tour_subscribers" violates foreign key constraint "tour_tour_subscribers_subscribers_id_fkey"
DETAIL: Key (subscribers_id)=(10) is not present in table "tour_subscribers".
私はDjangoが初めてで、これを修正する方法がわかりません。