Creating a Django cache table using south?

We use the South for our schemes and data. Now I need to enable the cache in Django, which is pretty simple to do. It made me use manage.py createcachetable cache_tablein my terminal. Although I would like to automate this process with the South. Is there a way to create a cache table using South?

+3
source share
1 answer

Create a new yugatic migration (just an empty migration):
python manage.py datamigration <app> create_cache_table

Edit the generated migration. I just named the cache table cache.

import datetime
from south.db import db
from south.v2 import DataMigration
from django.db import models
from django.core.management import call_command # Add this import

class Migration(DataMigration):
    def forwards(self, orm):
        call_command('createcachetable', 'cache')

    def backwards(self, orm):
        db.delete_table('cache')

    ...

, . import dbs db. : https://docs.djangoproject.com/en/dev/topics/cache/#multiple-databases.

import datetime
from south.db import dbs # Import dbs instead of db
from south.v2 import DataMigration
from django.db import models
from django.core.management import call_command # Add this import

class Migration(DataMigration):
    def forwards(self, orm):
        call_command('createcachetable', 'cache', database='other_database')

    def backwards(self, orm):
        dbs['other_database'].delete_table('cache')

    ...
+3

All Articles