Django South没有为user_profiles创建表

时间:2012-04-27 04:38:01

标签: python django django-south

我想重置我的Django项目的数据库,所以我做了以下步骤:

  1. 删除了我的SQLite数据库
  2. python manage.py syncdb
  3. python manage.py migrate users --fake
  4. 创建新帐户并登录后,收到以下错误消息:

    no such table: users_userprofile
    

    以下是我的用户model.py的样子:

    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)
    

    因此,有一个UserProfile类,但South似乎没有使表保存用户配置文件。当我python manage.py schemamigration users --auto时,它表示似乎没有任何改变。如何创建userprofiles表?

3 个答案:

答案 0 :(得分:6)

我有同样的问题。事实证明,使用South时存在循环依赖性。要解决此问题,请不要在运行syncdb时创建超级用户,而是运行:

python manage.py createsuperuser
使用syncdb创建数据库后

。此时,您的配置文件表将被创建,post_save信号将成功。

答案 1 :(得分:0)

尝试在不使用--fake选项的情况下迁移表。如果您在数据库中应用了更改但在南__migrationhistory表中没有更改,则假是有用的。

答案 2 :(得分:0)

以下内容适用于某些人:

python manage.py schemamigration myapp --initial
python manage.py migrate myapp