在这种情况下,“ foo_bar”实际上是“ links_userprofile_favorite_feeds”。
问题是,当我进入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)
我懂了
ProgrammingError: relation "links_userprofile_favorite_feeds" does not exist LINE 1: ..."links_userprofile_favorite_feeds"."feed_id" FROM "links_use...
以下是相关文件和回溯:
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)
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',)
迁移中似乎存在该关系,但是manage.py syncdb, manage.py makemigrations, manage.py migrate,所有关系都不起作用(没有要应用的迁移)。
manage.py syncdb, manage.py makemigrations, manage.py migrate
有人可以帮忙吗?我想建立关系"links_userprofile_favorite_feeds."
"links_userprofile_favorite_feeds."
固定。
对于将来遇到此问题的人:
通过执行以下操作,删除“链接”应用程序的所有迁移:
from django.db.migrations.recorder import MigrationRecorder
MigrationRecorder.Migration.objects.filter(app=’links’).delete()
向前迁移 manage.py migrate
manage.py migrate