djangodjango-modelsdjango-cache

How do I delete the django cache database table?


I have been using django's database caching as shown here: https://docs.djangoproject.com/en/4.1/topics/cache/#database-caching

Recently I have migrated to redis caching, but I still have the cache table in my database from the command python manage.py createcachetable.

How can I safely delete this table?


Solution

  • You can just create a custom empty migration with

    ./manage.py makemigrations --empty myApp

    And then add raw SQL to drop the table.

    
    from django.db import migrations
    
    
    class Migration(migrations.Migration):
        dependencies = [
            ("myApp", "latest_migration"),
        ]
    
        operations = [
            migrations.RunSQL("DROP TABLE IF EXISTS cache_table_name;"),
        ]