D
D
dashkevi4mike2015-06-25 09:41:35
Django
dashkevi4mike, 2015-06-25 09:41:35

ValueError: Cannot serialize when running makemigrations?

Moved a project from Django 1.6 to Django 1.8. Tried to run the makemigrations command. Got the following error.

Traceback (most recent call last):
  File "/home/camaro/programming/imedrese/master/manage.py", line 14, in <module>
    execute_from_command_line(sys.argv)
  File "/home/camaro/programming/imedrese/master/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/home/camaro/programming/imedrese/master/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/camaro/programming/imedrese/master/local/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/camaro/programming/imedrese/master/local/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
    output = self.handle(*args, **options)
  File "/home/camaro/programming/imedrese/master/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 143, in handle
    self.write_migration_files(changes)
  File "/home/camaro/programming/imedrese/master/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 171, in write_migration_files
    migration_string = writer.as_string()
  File "/home/camaro/programming/imedrese/master/local/lib/python2.7/site-packages/django/db/migrations/writer.py", line 146, in as_string
    operation_string, operation_imports = OperationWriter(operation).serialize()
  File "/home/camaro/programming/imedrese/master/local/lib/python2.7/site-packages/django/db/migrations/writer.py", line 104, in serialize
    _write(arg_name, arg_value)
  File "/home/camaro/programming/imedrese/master/local/lib/python2.7/site-packages/django/db/migrations/writer.py", line 68, in _write
    arg_string, arg_imports = MigrationWriter.serialize(item)
  File "/home/camaro/programming/imedrese/master/local/lib/python2.7/site-packages/django/db/migrations/writer.py", line 283, in serialize
    item_string, item_imports = cls.serialize(item)
  File "/home/camaro/programming/imedrese/master/local/lib/python2.7/site-packages/django/db/migrations/writer.py", line 354, in serialize
    return cls.serialize_deconstructed(path, args, kwargs)
  File "/home/camaro/programming/imedrese/master/local/lib/python2.7/site-packages/django/db/migrations/writer.py", line 248, in serialize_deconstructed
    arg_string, arg_imports = cls.serialize(arg)
  File "/home/camaro/programming/imedrese/master/local/lib/python2.7/site-packages/django/db/migrations/writer.py", line 438, in serialize
    "topics/migrations/#migration-serializing" % (value, get_docs_version())
ValueError: Cannot serialize: <bound method AboutManager.default of <articles.models.AboutManager object at 0x9c687ac>>

models that the following swear at:
class AboutManager(models.Manager):
    def default(self):
        default = self.all()[:1]
        if len(default) == 0:
            return None
        else:
            return default[0]


class About(models.Model):
    name = models.CharField(max_length=50, verbose_name=_("name"))
    url = models.SlugField(blank=True, verbose_name=_("url"))
    is_live = models.BooleanField(default=True, blank=True, verbose_name=_("is_live"))
    meta_description = models.TextField(blank=True, verbose_name=_("Meta description"))
    meta_keywords = models.TextField(blank=True, verbose_name=_("Meta keywords"))
    title = models.CharField(blank=True, max_length=50, verbose_name=_("Page name"))
    welcome_text = models.TextField(blank=True, verbose_name=_("Welcome text"))

    objects = AboutManager()

    def random_url(self):
        url = urandom(7).encode('hex')
        while About.objects.filter(url=url).exists():
            url = urandom(7).encode('hex')
            return urlcd
    def make_url(self):
        if not self.url:
            url = translit_url(self.name)
            if About.objects.filter(url=url).exists():
                url = About.random_url
            return url
        return self.url

    class Meta:
        verbose_name = _('Article about')
        verbose_name_plural = _('Articles about')

    def __unicode__(self):
        if self.is_live:
            return u'%s (live)' % self.name
        else:
            return self.name

Tell me, please, why did he not like the manager?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Seva Zhidkov, 2015-06-25
@Shamoi

What version of Django do you have?
A similar problem was discussed here, it seems to have been fixed, if I understood correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question