I'm trying to update from Django 1.7 to Django 1.8
One of my models uses CurrentSiteManager from django.contrib.sites.managers like so:
from django.contrib.sites.managers import CurrentSiteManager
class NewsQuerySet(models.QuerySet):
#...
class News(models.Model):
#...
objects = NewsQuerySet.as_manager()
on_site = CurrentSiteManager.from_queryset(NewsQuerySet)()
When I try to run migrations (makemigrations or migrate) I get:
ValueError: Could not find manager CurrentSiteManagerFromNewsQuerySet in django.db.models.manager. Please note that you need to inherit from managers you dynamically generated with 'from_queryset()'.
If I remove the on_site manager, everything works fine.
Any ideas how to overcome this?
There's a better way to do this.
from django.db import models
class NewsManager(models.Manager.from_queryset(NewsQuerySet)):
use_in_migrations = True
class News(models.Model):
...
objects = NewsManager()
Then you can do whatever additional things you want with CurrentSiteManager objects.
Turns out, since Django 1.8 we can serialize Managers using use_in_migrations.
And the CurrentSiteManager is marked with use_in_migrations = True
So the fix is to set back use_in_migrations = False. I did it this way:
class NewsSiteManager(CurrentSiteManager.from_queryset(NewsQuerySet)):
use_in_migrations = False
class News(models.Model):
#...
objects = NewsQuerySet.as_manager()
on_site = NewsSiteManager()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With