I wanted to reset my Django project’s database, so I did the following steps:
- Deleted my SQLite database
- Did
python manage.py syncdb - Did
python manage.py migrate users --fake
After I create a new account and login, I get the following error message:
no such table: users_userprofile
Here is what my users model.py looks like:
class UserProfile(models.Model):
user = models.OneToOneField(User)
joined_goals = models.ManyToManyField(Goal, related_name="joined_goals")
followingGoals = models.ManyToManyField(Goal, related_name="following_goals")
def __unicode__(self):
return self.user.username
def get_goals(self):
try:
goals = Goal.objects.filter(user=self.user)
return goals
except Goal.DoesNotExist:
return []
def create_user_profile(sender, instance, created, **kwargs):
if created:
userProfile = UserProfile.objects.create(user=instance)
post_save.connect(create_user_profile, sender=User)
So, there is a UserProfile class, but South did not seem to make the table to hold the user profiles. When I do python manage.py schemamigration users --auto, it says that nothing has seemed to changed. How do I get it to create the userprofiles table?
I had this exact same problem. Turns out that there is a circular dependency of sorts when using South. To get around this problem, don’t create a superuser when you run syncdb, but instead run:
after you have created the database with syncdb. At this point, your profile table will have been created, and the post_save signal will succeed.