2

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()
....

I updated the above model to:

....
title = models.CharField()
author = models.ForeignKey(User, on_delete=models.CASCADE)
introduction = models.charfield()
body = models.TextField()
....

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. What can I do to solve this problem?

1
  • 1
    What you've provided isn't enough to give an answer. you need to provide views template and relevant details Commented Dec 30, 2020 at 14:10

1 Answer 1

1

After update models, you have to run the commands:

python manage.py makemigrations

python manage.py migrate
  • makemigrations command will check the diffs between your current model in database and model in python code.

  • migrate will really run the migration to reflect your model with database model.

You can find more information about makemigrations and migrate in django documentation about makemigrations and migrate.

Sign up to request clarification or add additional context in comments.

1 Comment

I ran both commands after updating it and the migration was successful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.