Django.core.exceptions.fielderror: Unknown Field(s) (academic_grade) Specified For User
Solution 1:
When you run -
python manage.py migrate
django will migrate all inbuilt models present in the following apps-
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes'
From django.contrib.auth app , there is a inbuilt table User , that have the following fields -
Column |
id
password
last_login
is_superuser
username
first_name
last_name
email
is_staff
is_active
date_joined
I am afraid , this is being picked by the django (either by wrongly import or by running migration command before actually creating your own User). The latter one will actually create User before your models.
Therefore , I would suggest you to either cross check your import or try giving some other name to your user.For e.g
classPersonForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput)
classMeta:
model = Personfields= ['first_name', 'last_name',
'username', 'email', 'academic_grade',]
Let me know, if it helps or correct me if you think so !
Thanks
Solution 2:
One more possible scenario is you might forget to add AUTH_USER_MODEL
in your setting. (It happens to me many times).
I will suggest you not to use User as class name if you build a customUser class.
class CustomUser(AbstractBaseUser, PermissionsMixin):
username = models.CharField(max_length=30, blank=True, default='')
academic_grade = models.CharField(choices=GRADE_CHOICES, default='')
from django.contrib.auth importget_user_modelUser= get_user_model()
classUserForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput)
classMeta:
model = Userfields= ['first_name', 'last_name',
'username', 'email', 'academic_grade',]
and in setting.py add
AUTH_USER_MODEL = 'appName.CustomUser'
In case you forget to add AUTH_USER_MODEL
, when you migrate, the default django auth field are created. You can verify those in the migration file. As such any custom fields you try to call in form.py will nor be available.
Post a Comment for "Django.core.exceptions.fielderror: Unknown Field(s) (academic_grade) Specified For User"