Hello Django Forum!
I have a project that I am working on and the error message reads
OperationalError at /admin/blog/post/add/
table blog_post has no column named author_id
Request Method: | POST |
---|---|
Request URL: | http://127.0.0.1:8000/admin/blog/post/add/ |
Django Version: | 4.2.3 |
Exception Type: | OperationalError |
Exception Value: | table blog_post has no column named author_id |
Here is my models.py
from django.db import models
from django.urls import reverse
# Create your models here.
class Post(models.Model):
# primary key automatically placed here auto incrementing.
title = models.CharField(max_length=200)
author = models.ForeignKey(
"auth.User",
on_delete=models.CASCADE,
)
body = models.TextField()
# this function will make a human readable version of the title field of any blog post.
def __str__(self):
return self.title
"""We also add a get_absolute_url() method, which we haven't seen before, that tells Django how
to calculate the canonical URL for our model object. It says to use the URL named post_detail and pass in the pk"""
def get_absolute_url(self): # new
return reverse("post_detail", kwargs={"pk": self.pk})
I thought django gave id’s when they created tables. If I want to create an author id column for table_blog post how would I do that?
Per the instructions it says that I will have an error if I DO NOT enter in an author name and that I can set the values to null.
When I access the Django admin interface to add a post it has me fill in a title box, an author box, and an body box. when i select the drop down for author it does not let me create a new author, it instead tells me I can add in users as authors. I try to complete the process of filling in the fields and using a user and it results in an error.