Hello. I study Django by djangogirls. I ran into a mistake. Stuck on the Django ORM section.

It's simple: we import the Post model from blog.models. Let's try to get all the blog entries again:

>>>Post.objects.all() [<Post: my post title>, <Post: another post title>] 

and I have:

 Post.objects.all() [] 

... and further error below:

  >>> me = User.objects.get(username='ola') Traceback (most recent call last): File "<console>", line 1, in <module> File "/home/loma/djanjogirls/myvenv/lib/python3.4/site-packages/django/db/models/manager.py", line 122, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "/home/loma/djanjogirls/myvenv/lib/python3.4/site-packages/django/db/models/query.py", line 387, in get self.model._meta.object_name django.contrib.auth.models.DoesNotExist: User matching query does not exist. 

git - http://goo.gl/Z0yZj3

  • What is the mistake? I see an empty array. - Invision
  • An empty list indicates that there are no records in the table. They just need to create. - Mr Fix
  • @Invision added egor below - Lita Litar
  • @Mrfix How? (myvenv) ~ / djangogirls $ python manage.py makemigrations blog (myvenv) ~ / djangogirls $ python manage.py migrate blog did not help - Lita Litar

2 answers 2

An empty list indicates that there are no records in the table. They just need to create.

Ways to create:

 p = Post(autor=user, title="заголовок", text="текст") p.save() p = Post.objects.create(autor=user, title="заголовок", text="текст") 

After that, when sampling the list will be with the results.

The first user is better to create a superuser from the command line. Go to the folder with the manage.py file and write manage.py createsuperuser

  • I do this further in the tutorial - tutorial.djangogirls.org/ru/django_orm Post.objects.create(author=me, title='Sample title', text='Test') >>> from django.contrib.auth.models import User >>> User.objects.all() me = User.objects.get(username='ola') And then the error above is django.contrib.auth.models.DoesNotExist: User matching query does not exist. - Lita Litar
  • This is impossible, because the DoesNotExist error when trying to find a user means that such a record was not found. And if it is not found, it means it is not there. Look first if your models are in the database, because the django does not find anything in both queries. - Mr Fix

Judging by the description of the problem, you did not do the migration for the default project tables. Repeat creation of migrations without arguments

 python manage.py makemigrations python manage.py migrate