You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django 2.0.4博客应用报错:relation 'blog_blog' does not exist

Fixing "relation 'blog_blog' does not exist" Error in Django 2.0.4

Hey there, let's sort out this frustrating error you're facing with your Django blog app! That "relation does not exist" message almost always means your database doesn't have the table corresponding to your Blog model yet. Here's how to fix it step by step:

Step 1: Verify your app is registered in settings

First, double-check that your blog app is added to INSTALLED_APPS in your project's settings.py file. Django won't process migrations for apps that aren't listed here:

INSTALLED_APPS = [
    # ... other default apps like 'django.contrib.admin'
    'blog',  # Make sure this line exists!
]

Step 2: Generate migration files

If you haven't already, tell Django to create migration scripts based on your Blog model. Run this command in your terminal:

python manage.py makemigrations

You should see output confirming a migration was created for the blog app (something like Migrations for 'blog': blog/migrations/0001_initial.py).

Step 3: Apply migrations to the database

Next, execute those migrations to actually create the blog_blog table in your database:

python manage.py migrate

This command will apply all pending migrations, including the one for your Blog model.

If the problem persists: Reset migrations (dev environments only!)

If you're still getting the error, it might be due to a mismatch between your migration files and the database state. Only do this if you're working in a development environment (never touch production data this way!):

  • Back up your database first (just in case you need to revert)
  • Delete all files in your blog/migrations directory except __init__.py
  • Drop your existing database (or use python manage.py flush if you want to keep the database but clear all data)
  • Re-run these commands in order:
    python manage.py makemigrations
    python manage.py migrate
    

Your Blog model looks correctly structured from the code snippet you shared, so these steps should get your table created and resolve the error.

内容的提问来源于stack exchange,提问作者Serhii

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:06:52