簡體   English   中英

Django South沒有為user_profiles創建表

[英]Django South is not creating a table for user_profiles

我想重置我的Django項目的數據庫,所以我做了以下步驟:

  1. 刪除了我的SQLite數據庫
  2. python manage.py syncdb
  3. python manage.py migrate users --fake是否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表?

我有同樣的問題。 事實證明,使用South時存在循環依賴性。 要解決此問題,請不要在運行syncdb時創建超級用戶,而是運行:

python manage.py createsuperuser

使用syncdb創建數據庫之后。 此時,您的配置文件表將被創建,post_save信號將成功。

嘗試在沒有--fake選項的情況下遷移表。 如果您在數據庫中應用了更改但在south_migrationhistory表中沒有應用,則假是有用的。

以下內容適用於某些人:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM