django - Run migrations without loading views/urls -
i have following code in 1 of views:
@ratelimit(method='post', rate=get_comment_rate()) def post_comment_ajax(request): ...
however, upon initial ./manage.py migrate
, get_comment_rate() requires table in database, i'm unable run migrations create tables. ended following error:
django.db.utils.programmingerror: relation .. not exist
is possible run migrations without loading views or there better way?
running migrations triggers system checks run, causes views load. there isn't option disable this.
it looks ratelimit
library allows pass callable.
@ratelimit(method='post', rate=get_comment_rate) def post_comment_ajax(request):
this call get_comment_rate
when view runs, rather when module loads. advantage (value won't stale) or disadvantage (running sql query every time view runs affect performance.
in general, want avoid database queries when modules load. causing issues migrations, can cause issues when running tests -- queries can go live db before test database has been created.
if ok risk, 1 option catch exception in decorator:
def get_comment_rate(): try: ... except programmingerror: return '1/m' # or other default
Comments
Post a Comment