在这种情况下,“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
,都不起作用(不应用迁移)。
有人可以帮忙吗?我想创建关系"links_userprofile_favorite_feeds."
答案 0 :(得分:2)
固定。
对于将来遇到此问题的人:
通过执行以下操作删除“链接”应用的所有迁移:
from django.db.migrations.recorder import MigrationRecorder
MigrationRecorder.Migration.objects.filter(app='links').delete()
使用manage.py migrate