0
我已經看到了關於這個錯誤在Django很多問題,但我在一個損失,因爲據我所知,在我的數據庫中沒有表有SECTION_ID欄。我得到的錯誤,當用戶嘗試註冊和views.py嘗試創建一個用戶。我最近改變了在「個人資料」的模式在我的應用程序(檔案對象自動沿着用戶創建對象)有一個部分屬性,而不是一個SECTION_ID屬性,但我重置遷移和重建數據庫數倍。我認爲這可能是一個遷移問題,但我真的不知道。Django的完整性錯誤「列SECTION_ID「不能爲空」
下面是以前有個SECTION_ID屬性的剖面模型:
class Profile(models.Model):
"""
An extension of the built-in Django user model to allow for the different types of users
"""
USER_TYPES = (
('S', 'Student'),
('I', 'Instructor'),
('C', 'Client')
)
user = models.OneToOneField(User, on_delete=models.CASCADE)
user_type = models.CharField(max_length=1, choices=USER_TYPES)
section = models.ForeignKey(Section, default=None)
@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)
@receiver(post_save, sender=User)
def save_user_profile(sender, instance, **kwargs):
if instance.is_staff != 1:
instance.profile.save()
這裏是提高錯誤代碼:
new_user = User.objects.create_user(email, email=email, password=password)
「在我的數據庫中沒有表具有SECTION_ID列」,實際上就意味着在剖面模型的'section'列。你爲什麼不試試'節= models.ForeignKey(科空白=真,空=真)'? –
和'還設置默認值user_type' –
你是金丹@AvinashRaj生活! –