1

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."

Mike Johnson Jr
  • 776
  • 1
  • 13
  • 32
  • Its clearly a database issue, so u have either not created the migration, or have not migration folder in the app directory or the app isn't registered at INSTALLED_APP. and don't use syncdb. – ruddra Jan 06 '15 at 09:50
  • @ruddra The migration is shown in the migration file above. All necessary apps have been installed. Why shouldn't I use syncdb? – Mike Johnson Jr Jan 06 '15 at 23:37
  • [syncdb has been deprecated and replaced by migrate](http://django.readthedocs.org/en/latest/releases/1.7.html#schema-migrations) – ruddra Jan 07 '15 at 04:00

1 Answers1

2

Fixed.

For those with this problem in the future:

  1. Delete all links_* tables from the database (app was called 'links')
  2. Delete all migrations for the 'links' app by doing:

    from django.db.migrations.recorder import MigrationRecorder
    MigrationRecorder.Migration.objects.filter(app='links').delete()
    
  3. Migrated forward with manage.py migrate

bcb
  • 1,977
  • 2
  • 22
  • 21
Mike Johnson Jr
  • 776
  • 1
  • 13
  • 32