I am started learning Django, following instructions from the book titled “Django 4 by Example”.
In the first chapter, the author teaching us to build a blog. So far it works fine till I created my first blog post. The error massages are as below. Hoping the Discord community would help me. Thank you in advance.
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:|5.1|
|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.utils import timezone
from django.contrib.auth.models import User
class Post(models.Model):
class Status(models.TextChoices):
DRAFT = 'DF', 'Draft'
PUBLISHED = 'PB', 'Published'
title = models.CharField(max_length=250)
slug = models.SlugField(max_length=250)
author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='blog_posts')
body = models.TextField()
publish = models.DateTimeField(default=timezone.now)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
status = models.CharField(max_length=2, choices=Status.choices, default=Status.DRAFT)
class Meta:
ordering = ['-publish']
indexes = [models.Index(fields=['-publish'])]
def __str__(self):
return self.title
and here is admin.py
from django.contrib import admin
from .models import Post
admin.site.register(Post)