Skip to main content

Quick Diagnosis

1

Check Services

Verify PostgreSQL and Redis are running
2

Review Logs

Check fkapi/api.log and fkapi/logs/performance.log
3

Test Connections

Verify database and cache connections work
4

Check Environment

Ensure .env file has all required variables

Setup Issues

Database Connection Errors

Problem: django.db.utils.OperationalError: could not connect to serverSolutions:
  1. Verify PostgreSQL is running:
  1. Check database credentials in .env:
  1. Create database if missing:
  1. Test connection:
Problem: Database not created during setupSolution:

Redis Connection Errors

Problem: ConnectionError: Error connecting to RedisSolutions:
  1. Verify Redis is running:
  1. Check Redis URL in .env:
  1. Start Redis:
  1. Test connection:

Module Import Errors

Problem: ModuleNotFoundError: No module named 'core'Solutions:
  1. Ensure correct directory:
  1. Activate virtual environment:
  1. Install dependencies:
  1. Verify installation:

Runtime Issues

Rate Limit Exceeded

Problem: API returns 403 with rate limit errorSolutions:
  1. Wait for rate limit to reset (default: 1 hour)
  2. Increase rate limit in .env:
  1. Whitelist IP for testing (in .env):
  1. Check current rate limit status:
  1. Clear rate limit (development only):

Slow API Responses

Solutions:
  1. Check Redis cache is working:
  1. Check response time headers:
  1. Enable query logging (temporarily in settings.py):
  1. Review slow query logs:
  1. Warm cache:

Cache Not Working

Solutions:
  1. Verify Redis connection (see Redis section above)
  2. Check cache configuration in settings.py:
  1. Clear cache manually:
  1. Check cache keys:
  1. Test cache from Django shell:

Database Migration Errors

Problem: django.db.migrations.exceptions.InconsistentMigrationHistorySolutions:
  1. Check migration history:
  1. Fake migration (use with caution):
  1. Reset migrations (development only):
Solutions:
  1. Create migrations:
  1. Apply migrations:
  1. Check for conflicts:

Testing Issues

Tests Failing

Solutions:
  1. Check pytest.ini configuration:
  1. Run tests from project root:
  1. Clear test database:
  1. Verify test settings:

Coverage Not Working

Solutions:
  1. Install coverage tools:
  1. Run with coverage:
  1. Check configuration in pyproject.toml:

Scraping Issues

Scraping Fails with Connection Errors

Problem: requests.exceptions.ConnectionError or timeoutSolutions:
  1. Check internet connection
  2. Verify target website is accessible:
  1. Check proxy settings in core/http.py
  2. Increase timeout in .env:

HTML Parsing Errors

Solutions:
  1. Check if website structure changed
  2. Log raw HTML for debugging:
  1. Review HTML fixtures in tests
  2. Add defensive checks in parsers:

Duplicate Data Issues

Solutions:
  1. Check slug uniqueness constraints
  2. Use get_or_create() instead of create():
  1. Find duplicates:

API Issues

500 Internal Server Error

Solutions:
  1. Check Django logs:
  1. Enable DEBUG mode (temporarily in .env):
  1. Check database connection
  2. Verify environment variables:
  1. Test endpoint directly:

API Documentation Not Loading

Solutions:
  1. Verify Django Ninja is installed:
  1. Check URL configuration in fkapi/urls.py:
  1. Access correct URL:

Performance Issues

High Database Query Count

Solutions:
  1. Use select_related() for foreign keys:
  1. Use prefetch_related() for many-to-many:
  1. Check query count in response headers:
  1. Enable query logging (see Slow API Responses)

Memory Issues

Solutions:
  1. Use pagination for large datasets
  2. Process data in chunks:
  1. Clear cache periodically:
  1. Monitor with django-debug-toolbar (development)

Getting More Help

Check Logs

Review fkapi/api.log and fkapi/logs/performance.log

Enable Debug

Set DJANGO_DEBUG=True for detailed error messages

Documentation

Review other docs in /docs directory

GitHub Issues

Search existing issues or create new one

Common Error Messages

django.core.exceptions.ImproperlyConfigured

Usually means missing or incorrect settings. Check:
  • Environment variables in .env
  • Database configuration
  • Redis configuration

django.db.utils.IntegrityError

Database constraint violation. Check:
  • Unique constraints
  • Foreign key relationships
  • Required fields

ninja.errors.ValidationError

API request validation failed. Check:
  • Required parameters
  • Parameter types
  • Request body format

core.exceptions.ScrapingError

Scraping operation failed. Check:
  • Network connectivity
  • Target website availability
  • HTML structure changes

Still having issues? Open an issue on GitHub with:
  • Error message and full stack trace
  • Steps to reproduce
  • Environment details (OS, Python version, etc.)
  • Relevant logs