P
P
Phantom_sterben2019-05-30 21:17:30
Django
Phantom_sterben, 2019-05-30 21:17:30

How to call a newly added field in a class in Django?

models.py
role_type = models.CharField(max_length=40, verbose_name="User Role")
group = models.ForeignKey(Group, on_delete=models.PROTECT, default=1, verbose_name='Group')
views.py
user = User .objects.get(username='my_user')
profile = Profile.objects.get(user=user)
user_role_group = profile.role.group
Throws
Traceback error (most recent call last):
File "", line 1, in
AttributeError: 'Role' object has no attribute 'group'
The group field was added later.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FulTupFul, 2019-05-30
@FulTupFul

You need to run migrations
python manage.py makemigrations app_name
python manage.py migrate

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question