In this case, "foo_bar" is actually "links_userprofile_favorite_feeds".
The problem is, when I go into manage.py shell:
manage.py shell
from django.contrib.auth.models import User
from feeds.models import feed
p = User.objects.get(username='myuser')
p.save()
q = Feed.objects.get(title='myfeed')
q.save()
p.userprofile.favorite_feed.add(q)
I get
the error:
ProgrammingError: relation "links_userprofile_favorite_feeds" does not exist
LINE 1: ..."links_userprofile_favorite_feeds"."feed_id" FROM "links_use...
Here are the relevant files and traceback:
links.models.py
class UserProfile(models.Model):
user = models.OneToOneField(User,unique=True)
bio = models.TextField(null=True)
thumbnail = models.ImageField(upload_to="uploaded_files/")
favorite_feeds = models.ManyToManyField(Feed)
feeds.models.py
class Feed(models.Model):
title = models.CharField(max_length=25)
slug = models.SlugField(max_length=25)
def save(self, *args, **kwargs):
if not self.slug:
#Newly created object, so set slug
self.slug = slugify(self.title)
super(Feed,self).save(*args,**kwargs)
def __unicode__(self):
return self.title
class Meta:
ordering = ('title',)
The relation seems to be present in the migration, but manage.py syncdb, manage.py makemigrations, manage.py migrate
, all do not work (no migrations to apply).
Can anyone help? I am wanting to create the relation "links_userprofile_favorite_feeds."
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…