articles_article.author_id Error

Asked

Viewed 43 times

-1

I’ve been following the blog creation tutorial using the previous version of Django 2.0 (this one here: https://youtu.be/zJWhizYFKP0), however I use version 2.0, in the process I have been making the necessary syntax changes for the code to work, however I arrived at a part where the 'articles_article.author_id' of the error, I have been reading the documentation of the site Django and looking for answers, but I couldn’t find what in my lines was wrong, in theory it was supposed to work. the error only occurs in the pages with the lists of the articles, either in the one created on the site or in the one that comes ready from Django admin, article creation and home are working. I will leave the error following the copy of the codes below, I will be very grateful if you can help me:

ERROR:

OperationalError at /articles/
no such column: articles_article.author_id
Request Method: GET
Request URL:    http://127.0.0.1:8000/articles/
Django Version: 2.2.1
Exception Type: OperationalError
Exception Value:    
no such column: articles_article.author_id
Exception Location: C:\Users\daniel\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\sqlite3\base.py in execute, line 383
Python Executable:  C:\Users\daniel\AppData\Local\Programs\Python\Python37\python.exe
Python Version: 3.7.2
Python Path:    
['C:\\Users\\daniel\\site\\djangosite',
 'C:\\Users\\daniel\\AppData\\Local\\Programs\\Python\\Python37\\python37.zip',
 'C:\\Users\\daniel\\AppData\\Local\\Programs\\Python\\Python37\\DLLs',
 'C:\\Users\\daniel\\AppData\\Local\\Programs\\Python\\Python37\\lib',
 'C:\\Users\\daniel\\AppData\\Local\\Programs\\Python\\Python37',
 'C:\\Users\\daniel\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages']
Server time:    Mon, 1 Jul 2019 16:12:41 +0000
Error during template rendering
In template C:\Users\daniel\site\djangosite\templates\base_layout.html, error at line 6

no such column: articles_article.author_id
1   {% load static from staticfiles %}
2   <!DOCTYPE html>
3   <html lang="en" dir="ltr">
4     <head>
5       <meta charset="utf-8">
6       <title>Articles</title>
7       <link rel="stylesheet" href="{% static 'styles.css' %}">
8     </head>
9     <body>
10      <div class="wrapper">
11        <h1><a href="{% url 'articles:list' %}">Articles</a>
12          <nav>
13            <ul>
14              <li>
15                <form class="logout-link" action="{% url 'accounts:logout' %}" method="post">
16                  {% csrf_token %}
Traceback Switch to copy-and-paste view
C:\Users\daniel\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\utils.py in _execute
                return self.cursor.execute(sql, params) …
▶ Local vars
C:\Users\daniel\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\sqlite3\base.py in execute
        return Database.Cursor.execute(self, query, params) …
▶ Local vars
The above exception (no such column: articles_article.author_id) was the direct cause of the following exception:
C:\Users\daniel\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py in inner
            response = get_response(request) …
▶ Local vars
C:\Users\daniel\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py in _get_response
                response = self.process_exception_by_middleware(e, request) …
▶ Local vars
C:\Users\daniel\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py in _get_response
                response = wrapped_callback(request, *callback_args, **callback_kwargs) …
▶ Local vars
C:\Users\daniel\site\djangosite\articles\views.py in article_list
    return render(request, 'articles/article_list.html', {'articles': articles}) …
▼ Local vars
Variable    Value
articles    
Error in formatting: OperationalError: no such column: articles_article.author_id
request 
<WSGIRequest: GET '/articles/'>
  • You executed the Migrations of its application before running it?

  • yes but it speaks that it has nothing to migrate

  • Hello friend, I just solved the problem, in the end it was conflict with old articles that there were no author, they were created in tests before adding the function, after deleting the database file, and redoing with migrate, it worked again. Thanks for the help. :)

1 answer

0


It seems your exception was generated because your template is not finding the field rendered by view. Django is not finding the column in the database articles_article.author_id.

If you can, post your view article_list and the template for verification.

Anyway, check if your template has the expression articles_article.author_id. If you remove the article leaving it so: articles.author_id and see if it works.

Att.

  • Hello friend, I had not attacked me for this, after reading your comment I went to make a search, and found that the comflito was in the database, where there were old test articles, before putting to add the author, after deleting my old database and creating another one with migrate has been working again. Thank you so much for your help. :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.