Mathijs
Mathijs

Reputation: 471

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?

Upvotes: 1

Views: 258

Answers (1)

tarikki
tarikki

Reputation: 2319

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;"),
    ]

Upvotes: 0

Related Questions