Reputation: 483
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.
Upvotes: 2
Views: 1004
Reputation: 473873
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.
Upvotes: 1