【发布时间】:2013-10-28 23:01:53
【问题描述】:
我想重置我的 Django 项目的数据库,所以我做了以下步骤:
- 删除了我的 SQLite 数据库
- 有
python manage.py syncdb - 有
python manage.py migrate users --fake
创建新帐户并登录后,我收到以下错误消息:
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 表?
【问题讨论】:
-
你为什么使用
--fake?这实际上并没有进行迁移... -
旁注:您的 get_goals 函数永远不会引发 DoesNotExist 异常。如果没有匹配的目标,你只会得到一个空的查询集。
-
你运行
./manage.py convert_to_south users了吗?在尝试生成架构迁移之前,您可能需要这样做 -
当我执行 convert_to_south 用户时,我收到此错误:此应用程序已由 South 管理。
标签: python django django-south