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

Django静态预编译报错:relation 'static_precompiler_dependency'不存在

Fixing "relation 'static_precompiler_dependency' does not exist" Error in Django SCSS Compilation

You're hitting an error where Django throws:

Exception Value: relation "static_precompiler_dependency" does not exist

even though you can see the COMPILED folder generated. Let's break down why this happens and how to fix it:

Root Cause

The django-static-precompiler library uses the static_precompiler_dependency database table to track dependencies between your SCSS files (like imports). Even if it can compile your files initially, it needs this table to handle subsequent requests and dependency checks—missing it causes the runtime error.

Step-by-Step Fixes

1. Run the Required Database Migrations

The library includes built-in migration files to create this table. Run this command in your project root:

python manage.py migrate static_precompiler

This will create the static_precompiler_dependency table in your database.

2. Confirm static_precompiler is in Your Installed Apps

Make sure you've added the app to your INSTALLED_APPS in settings.py—this is necessary for Django to load its migrations and functionality:

INSTALLED_APPS = [
    # Core Django apps (e.g., 'django.contrib.admin', 'django.contrib.auth')
    # Your custom apps
    'static_precompiler',  # Add this line if missing
]

Your current STATIC_ROOT points to static/css, which overlaps with your STATICFILES_DIRS (already pointing to the project's static folder). STATIC_ROOT is meant to be a separate directory where Django collects all static files for production deployment. Update it to avoid conflicts:

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

Verify the Fix

After completing these steps, restart your Django development server and refresh your page. The error should be gone, and your compiled CSS should load correctly.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 07:59:29