Environment:
Request Method: GET
Request URL: http://localhost:8000/posts/2/
Django Version: 5.1.4
Python Version: 3.13.1
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'forum.apps.ForumConfig',
'accounts.apps.AccountsConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Template error:
In template D:\projects\DJANGO\myforum\templates\forum\post_detail.html, error at line 47
no such column: forum_comments.user_id
37 : {% csrf_token %}
38 : <div>
39 : <label>
40 : <textarea name="text_comments" placeholder="Ваш комментарий..."></textarea>
41 : </label>
42 : </div>
43 : <div><input type="submit"></div>
44 : </form>
45 : </div>
46 : <div>
47 : {% for comment in post.comments_set.all reversed %}
48 : <div class="view-comment">
49 : <h4>{{ comment.user.username }}</h4>
50 : <p><i>{{ comment.text_comments }}</i></p>
51 : </div>
52 : {% endfor %}
53 : </div>
54 : {% else %}
55 : <h1>Вы не авторизованы</h1>
56 : <form action="{% url 'login' %}" method="post">
57 : {% csrf_token %}
Traceback (most recent call last):
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\db\backends\utils.py", line 105, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\db\backends\sqlite3\base.py", line 354, in execute
return super().execute(query, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The above exception (no such column: forum_comments.user_id) was the direct cause of the following exception:
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\views\generic\base.py", line 104, in view
return self.dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\views\generic\base.py", line 143, in dispatch
return handler(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\forum\views.py", line 23, in get
return render(request, 'forum/post_detail.html', {'post': post})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\shortcuts.py", line 25, in render
content = loader.render_to_string(template_name, context, request, using=using)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\template\loader.py", line 62, in render_to_string
return template.render(context, request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\template\backends\django.py", line 107, in render
return self.template.render(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\template\base.py", line 171, in render
return self._render(context)
^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\template\base.py", line 1008, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\template\base.py", line 969, in render_annotated
return self.render(context)
^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\template\defaulttags.py", line 327, in render
return nodelist.render(context)
^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\template\base.py", line 1008, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\template\base.py", line 969, in render_annotated
return self.render(context)
^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\template\defaulttags.py", line 199, in render
len_values = len(values)
^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\db\models\query.py", line 382, in __len__
self._fetch_all()
^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\db\models\query.py", line 1928, in _fetch_all
self._result_cache = list(self._iterable_class(self))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\db\models\query.py", line 91, in __iter__
results = compiler.execute_sql(
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\db\models\sql\compiler.py", line 1574, in execute_sql
cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\db\backends\utils.py", line 122, in execute
return super().execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\db\backends\utils.py", line 79, in execute
return self._execute_with_wrappers(
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\db\backends\utils.py", line 92, in _execute_with_wrappers
return executor(sql, params, many, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\db\backends\utils.py", line 100, in _execute
with self.db.wrap_database_errors:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\db\utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\db\backends\utils.py", line 105, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\projects\DJANGO\myforum\.venv\Lib\site-packages\django\db\backends\sqlite3\base.py", line 354, in execute
return super().execute(query, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Exception Type: OperationalError at /posts/2/
Exception Value: no such column: forum_comments.user_id
python manage.py makemigrations
выдает