django-rest-auth
django-rest-auth copied to clipboard
Custom model FieldDoesNotExist
Hi all, thanks for the great lib. If someone uses a custom model that has, for example, email and password and no username and try to use the library, it will encounter a django.core.exceptions.FieldDoesNotExist: User has no field named 'username'. The error is generated by django-allauth not by django-rest-auth and can be easily solved by setting the following fields in settings.py.
# On settings.py
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = 'email'
A better explanation of those settings can be found in https://django-allauth.readthedocs.io/en/latest/advanced.html
It would be nice to put this somewhere on the docs. I can set it up. What do you think?
Thanks.
Thanks, very helpful ! Just wanted to point out that a full list of settings can be found here : https://django-allauth.readthedocs.io/en/latest/configuration.html
After adding this contants to settings.py I am experiencing this issue, here is my traceback I am using AbstractUser model class Exception in thread django-main-thread: Traceback (most recent call last): File "/home/tomms/.local/share/virtualenvs/article-uLOaw2Hi/lib/python3.9/site-packages/django/db/models/options.py", line 672, in get_field return self.fields_map[field_name] KeyError: 'username'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/threading.py", line 973, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.9/threading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File "/home/tomms/.local/share/virtualenvs/article-uLOaw2Hi/lib/python3.9/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/home/tomms/.local/share/virtualenvs/article-uLOaw2Hi/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 134, in inner_run
self.check(display_num_errors=True)
File "/home/tomms/.local/share/virtualenvs/article-uLOaw2Hi/lib/python3.9/site-packages/django/core/management/base.py", line 487, in check
all_issues = checks.run_checks(
File "/home/tomms/.local/share/virtualenvs/article-uLOaw2Hi/lib/python3.9/site-packages/django/core/checks/registry.py", line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/home/tomms/.local/share/virtualenvs/article-uLOaw2Hi/lib/python3.9/site-packages/django/core/checks/urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "/home/tomms/.local/share/virtualenvs/article-uLOaw2Hi/lib/python3.9/site-packages/django/core/checks/urls.py", line 24, in check_resolver
return check_method()
File "/home/tomms/.local/share/virtualenvs/article-uLOaw2Hi/lib/python3.9/site-packages/django/urls/resolvers.py", line 480, in check
for pattern in self.url_patterns:
File "/home/tomms/.local/share/virtualenvs/article-uLOaw2Hi/lib/python3.9/site-packages/django/utils/functional.py", line 49, in get
res = instance.dict[self.name] = self.func(instance)
File "/home/tomms/.local/share/virtualenvs/article-uLOaw2Hi/lib/python3.9/site-packages/django/urls/resolvers.py", line 696, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/tomms/.local/share/virtualenvs/article-uLOaw2Hi/lib/python3.9/site-packages/django/utils/functional.py", line 49, in get
res = instance.dict[self.name] = self.func(instance)
File "/home/tomms/.local/share/virtualenvs/article-uLOaw2Hi/lib/python3.9/site-packages/django/urls/resolvers.py", line 689, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/local/lib/python3.9/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "
Add ACCOUNT_USER_MODEL_USERNAME_FIELD = None to your settings.py