2

I am trying to add to a Twitter Clone app I am making using Django (I am new to Django), and I am unable to add new objects to my "following" list because I get "no such column: twitterclone_userpro_following.otherprofile_id". In the ManyToMany Django information page, it appears as easy as using the add command. The following are the two classes and the code I am trying to use to add:

class OtherProfile(models.Model):
    username = models.CharField(max_length=30)
    def get_username(self):
    return username

class UserPro(models.Model):
    username = models.CharField(max_length=30)
    following = models.ManyToManyField(OtherProfile)

And the following is the code I am trying to use to add to the following column:

me = UserPro.objects.get(username="newuser1")
himher = OtherProfile.objects.get(username="newuser2")
me.following.add(himher)

I don't understand the advice most answers online have, which involves using South, and I assume there must be an easy way without it, because the Many-To-Many documentation does not use it.

sdotslezek
  • 483
  • 1
  • 6
  • 9

1 Answers1

1

It's a known django issue if you create your models, run syncdb and then add a ManyToManyField on one of your models. In this situation running syncdb again wouldn't help - it wouldn't pick and apply your model changes, see:

The best way to go is to start using South - it can track your model changes and apply them through the schema and data migrations mechanism. It's worth trying.

Just FYI, you can also create that necessary many-to-many table manually.

Hope that helps.

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • thank you! I installed south using easy_install, but now am running into "ImportError: No module named twitterclonesouth". Any idea how to combat this? – sdotslezek Mar 11 '14 at 04:09
  • @user3404392 that's a strange error. Do you have `south` in your `INSTALLED_APPS`? – alecxe Mar 11 '14 at 04:17
  • yes. I put it in my installed apps. When I remove it, that issue goes away – sdotslezek Mar 11 '14 at 04:34
  • @user3404392 the module name `twitterclonesouth` is very strange..have you followed [installation instructions](http://south.readthedocs.org/en/latest/installation.html)? – alecxe Mar 11 '14 at 04:36