Python Django,ManyToManyField-编程错误:关系foo_bar不存在。在迁移中识别,但从未创建关系
在本例中,“foo\u bar”实际上是“links\u userprofile\u favorite\u feed” 问题是,当我进入manage.py shell时: manage.py shell 我明白了 错误: 以下是相关文件和回溯: links.models.py feed.models.py 该关系似乎出现在迁移中,但是Python Django,ManyToManyField-编程错误:关系foo_bar不存在。在迁移中识别,但从未创建关系,python,sql,django,postgresql,django-models,Python,Sql,Django,Postgresql,Django Models,在本例中,“foo\u bar”实际上是“links\u userprofile\u favorite\u feed” 问题是,当我进入manage.py shell时: manage.py shell 我明白了 错误: 以下是相关文件和回溯: links.models.py feed.models.py 该关系似乎出现在迁移中,但是manage.py syncdb、manage.py makemigrations、manage.py migrate,所有这些都不起作用(没有要应用的迁移) 有人
manage.py syncdb、manage.py makemigrations、manage.py migrate
,所有这些都不起作用(没有要应用的迁移)
有人能帮忙吗?我想创建关系“links\u userprofile\u favorite\u feed。”已修复
对于将来有此问题的人:
from django.db.migrations.recorder import MigrationRecorder
MigrationRecorder.Migration.objects.filter(app='links').delete()
manage.py migrate向前迁移
这显然是一个数据库问题,因此你要么没有创建迁移,要么没有在应用程序目录中创建迁移文件夹,要么应用程序没有在已安装的应用程序中注册。并且不要使用syncdb。@ruddra迁移显示在上面的迁移文件中。所有必要的应用程序都已安装。为什么我不应该使用syncdb?
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',)
from django.db.migrations.recorder import MigrationRecorder
MigrationRecorder.Migration.objects.filter(app='links').delete()