我正在尝试创建自定义用户注册模型,但是当我尝试创建超级用户时,出现以下错误:
回溯(最近通话最近一次):
File "manage.py", line 15, in <module> execute_from_command_line(sys.argv)
File "/anaconda3/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/anaconda3/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/anaconda3/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv self.execute(*args, **cmd_options)
File "/anaconda3/lib/python3.6/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 59, in execute return super().execute(*args, **options) .
File "/anaconda3/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/anaconda3/lib/python3.6/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 117, in handle self.UserModel._default_manager.db_manager(database).get_by_natural_key(username)
File "/anaconda3/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 44, in get_by_natural_key
return self.get(**{self.model.USERNAME_FIELD: username})
File "/anaconda3/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/django/db/models/query.py", line 397, in get
num = len(clone)
File "/anaconda3/lib/python3.6/site-packages/django/db/models/query.py", line 254, in __len__
self._fetch_all()
File "/anaconda3/lib/python3.6/site-packages/django/db/models/query.py", line 1179, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/anaconda3/lib/python3.6/site-packages/django/db/models/query.py", line 53, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/anaconda3/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1068, in execute_sql
cursor.execute(sql, params)
File "/anaconda3/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/anaconda3/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/anaconda3/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/anaconda3/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/anaconda3/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/anaconda3/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/anaconda3/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 303, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such column: app_profile.password
models.py
class UserManager(BaseUserManager):
def create_user(self, username, email, password = None):
if not email:
raise ValueError("no email error")
user = self.model(username = username, email = self.normalize_email(email))
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, username, email, password=None):
user = self.create_user(username, email, password=password)
user.is_admin = True
user.save(using=self._db)
return user
class Profile(AbstractBaseUser):
username = models.CharField(unique = True, max_length = 300,blank=True,null=True)
email = models.EmailField(max_length=255, unique=True, default = "")
is_admin = models.BooleanField(default = False)
age = models.IntegerField(default=-1, blank=True)
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email']
objects = UserManager()
def __str__(self):
return self.email
@property
def is_admin(self):
return self.is_admin
我在设置中设置了AUTH_USER_MODEL ='app.Profile'。我什至在尝试输入密码之前都会遇到no column错误(在输入用户名后立即发生)。有小费吗?非常感谢。