Using python manage.py shell I managed to create the interactive terminal for django.
I created objects and I can see them when I run >>> Question.objects.all()
I see them all listed in the photo believe.
I try to update the field question with the command
>>> q = Question.objects.get(pk=1)
after that I get the error
What gives? I clearly have objects with a pk =1.
Why do you think you âclearly have an object with pk=1â?
Run the command:
[(q.id, q.question_text) for q in Question.objects.all()]
and report the output.
(q.id, q.question_text) for q in Question.objects.all()]
[(3, 'Who invented python?'), (4, 'This question was changed by dot notation on the object.'), (5, 'Who invented Django?')]
>>>
!!!
I did have two empty queryset objects that I had deleted because they were empty. It seems that the 3, and 4, in the output are the primary key indicators! I have unintentionally removed 1 and 2 Or rather created 2 that were empty, made a third fourth and fifth. and than deleted the first two. what should I make the primary keys for 3, who invented python to pk 1, and make my 4, âThis question was changed by dot notationâ to a 2.
(q.id, q.question_text) for q in Question.objects.all()]
[(3, 'Who invented python?'), (4, 'This question was changed by dot notation on the object.'), (5, 'Who invented Django?')]
>>>
!!!
I did have two empty queryset objects that I had deleted because they were empty. It seems that the 3, and 4, in the output are the primary key indicators! I have unintentionally removed 1 and 2 Or rather created 2 that were empty, made a third fourth and fifth. and than deleted the first two. what should I make the primary keys for 3, who invented python to pk 1, and make my 4, âThis question was changed by dot notationâ to a 2.
my solution was to go into the /admin with manage.py and delete all of the questions and start over. when I did so, I was sure to completely delete everything and than exit out of the admin terminal and go back into they python manage.py shell terminal and re create my objects. I am not certian if i have to do this everytime but this was a situation in which I created the objects many days ago and did not remember what the name of my object was. by deleting everything and going back to the shell command I was able to recreate a variable holding an object as I wanted it. It seems that deleting these keys did not work.
I wonder if there is a way to update these objects to what I want. for example pk 1 = what is your favorite programming language
Actually, you shouldnât care about what the ID value is at all. You let the database assign it as appropriate and let it go at that.
1 Like
going forward I will let it go