After updating posts model field in MySQL database using using Django framework, I'm unable to query posts from the Database. Whenever I run the command python manage.py runserver, all seems to be well with the server. However, when enter the post url to display the list of posts I uploaded on the database before updating the model field, I get 1054, "Uknown column 'start_post.author_id' in the 'field list' I have spent a couple of hours try to figure out why I'm getting the error but I still don't get it. In model.py I had:
title = models.CharField()
preamble= models.Charfield()
body = models.TextField()
createdAt = models.DateTimeField(auto_now_add=True, blank=True)
I updated the above model to:
title = models CharField()
author = models.ForeignKey(User, on_delete=models.CASCADE)
introduction
= models.charfield ()
body = models.TextField()
createdAt = models.DateTimeField(auto_now_add=True, blank=True)
def get_absolute(self):
return reverse ('post-details', kwarks={'pk': set.pk})
views.py
••••
class PostListView(Listview):
model = Post
template_name = 'start/start.html'
context_object_name = 'posts'
ordering = ['createdAt']
start.html
•••
{% for post in posts %}
<h3>{{ post.title }}</h3>
<i>{{ post.createdAt }} </I>
<p>{{ post.introduction }}</p>
<p>{{ post.body }}</p>
{% endfor %}
••••
before updating it everything was working appropriately. But after updating it I'm unable to access the list of posts on browser, from the url start/ as well as the post detail page. I didn't have the author field in the first model but I added it to the updated model. As a newbie in Django I don't know where I'm getting it wrong.
python manage.py makemigrationsand after thispython manage.py migrate, after this run your server againtracebackerrors1054, "Uknown column 'start_post.author_id' in the 'field list'