I am creating a form, inside forms.py I have:
class UserForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput)
class Meta:
model = User
fields = ['first_name', 'last_name',
'username', 'email', 'academic_grade',]
But I get the following error:
django.core.exceptions.FieldError: Unknown field(s) (academic_grade) specified for User
I check in the database and user table have the 'academic_grade' grade column
models.py
class User(AbstractBaseUser, PermissionsMixin):
username = models.CharField(max_length=30, blank=True, default='')
academic_grade = models.CharField(choices=GRADE_CHOICES, default='')
please guide me through this
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
class PersonForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput)
class Meta:
model = Person
fields = ['first_name', 'last_name',
'username', 'email', 'academic_grade',]
Let me know, if it helps or correct me if you think so !
Thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With