在我第一次这样做之前,我从未处理过文件上传,而是按照youtube上的说明进行操作。显然,当我在我的模型中添加FileField并尝试迁移时,它给了我一些例外,我不知道如何解决它。我试图删除参数,但它仍然给我一个错误。请帮助我(我使用django btw)
models.py
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
email = models.TextField(max_length=500, blank=True)
contact_number = models.CharField(max_length=30, blank=True)
profile_photo = models.FileField(null=True,blank=True)
@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):
instance.profile.save()
然后出现了这个我无法理解的错误
Running migrations:
Applying bartr.0011_profile_profile_photo...Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 337, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.IntegrityError: NOT NULL constraint failed: bartr_profile.profile_photo