无法删除django中的超级用户并导致错误django.db.utils.OperationalError:无此类列:Infrastructure_profile.slug [英] Can not delete superuser in django and a resulting error django.db.utils.OperationalError: no such column: infrastructure_profile.slug
问题描述
我想在创建了多个配置文件后向我的模型配置文件(扩展用户模型)添加一个子段字段,然后进入配置文件页面时出现错误,URL中的子段显示:
I wanted to add a slug field to my model Profile (that extends the User model) after I had several profiles created, then an error appeared when reaching the profile page with the slug in the url saying :
Django OperationalError: no such column: infrastructure_profile.slug
所以我在这里看到了此答案
so I looked here and saw this answer
,它建议我删除所有迁移文件以重新启动数据库,所以我做了
and it suggested I delete all my migrations files to restart the database , so I did
,然后出现了同样的错误,所以我认为我应该删除我已经拥有的所有没有超级用户字段的用户。
and then I got the same error , so I thought I should delete all the users I already have that didn't had the slug field already including the superuser.
所以我关注了这个答案
我遇到了这个错误
django.db.utils.OperationalError: no such column: infrastructure_profile.slug
任何想法
编辑
我的models.py包含模型配置文件像这样
My models.py contains the model Profile like so
class Profile(User):
user = models.OneToOneField(User, parent_link=True, on_delete=models.CASCADE)
bio = models.TextField()
slug = models.SlugField(unique=True, blank=True)
avatar_thumbnail = ProcessedImageField(upload_to='images/',
default='/images/default.png',
processors=[ResizeToFill(300, 300)],
format='JPEG',
options={'quality': 60})
location = models.TextField()
tags = models.ManyToManyField(Tag)
contact_information = models.TextField()
verified = models.BooleanField(default=False)
counter = models.IntegerField(default=0)
def __str__(self):
return self.user.username
def save(self, *args, **kwargs):
print('self.username')
print(self.user.username)
self.slug = self.user.username
super(Profile, self).save(*args, **kwargs)
def get_absolute_url(self):
return reverse('infrastructure:edit-user-profile', kwargs={'slug': self.slug})
推荐答案
我不应该从User模型继承Profile,而是应该按照此答案将用户自定义为
I shouldn't have inherited Profile from the User model and I should have customized the user to following this answer instead
https://stackoverflow.com/a/58904426/5752406
这篇关于无法删除django中的超级用户并导致错误django.db.utils.OperationalError:无此类列:Infrastructure_profile.slug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!