簡體   English   中英

使用South創建Django Cache表?

[英]Creating Django Cache table using South?

我們使用South來進行架構映射和數據遷移。 現在我需要在Django中啟用緩存,這很簡單。 這迫使我在終端中使用manage.py createcachetable cache_table 雖然我想與South自動化這個過程。 有沒有辦法可以使用South創建緩存表?

創建一個新的南數據遷移(只是空白遷移):
python manage.py datamigration <app> create_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')

    ...

如果您使用多個數據庫並需要定義要使用的數據庫。 請注意dbs的第二個import語句而不是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')

    ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM