Repository: translate/pootle

Issue:
Running migrate twice gives an error about changed models
If you run `migrate` a second time directly after an initial migration you will get the following error.

```
Running migrations:
  No migrations to apply.
  Your models have changes that are not yet reflected in a migration, and so won't be applied.
  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
```

`makemigrations` produces this file:

``` py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import pootle.core.markup.fields


class Migration(migrations.Migration):

    dependencies = [
        ('virtualfolder', '0001_initial'),
    ]

    operations = [
        migrations.AlterField(
            model_name='virtualfolder',
            name='description',
            field=pootle.core.markup.fields.MarkupField(help_text='Use this to provide more information or instructions. Allowed markup: HTML', verbose_name='Description', blank=True),
            preserve_default=True,
        ),
    ]
```

@unho Why are virtualfolders doing this?



Discussion:
That's because `MarkupField`'s `help_text` has a placeholder in it, and the initial migration contains `reStructuredText` as the value for the placeholder, whereas in your case the value is `HTML`. In other words, any `MARKUP_FILTER` setting other than `reStructuredText` (which is what @unho had at the time of creating the migration) will trigger this.

A similar thing happened with #3557.

I understand the problem, but I am not sure how to fix it. Subclassing `MarkupField` would require doing the same thing in all the other places where it is used.

@unho if that's what's required then yes.  It's more of an issue that post migration if you have `MARKUP_FILTER` set to anything but rST then you find migrations are now out of sync.  I guess its a bad side effect of `MarkupField`

It's not `MarkupField`'s side-effect but dynamic help text's. The same can happen for any field with dynamic values which are evaluated when models are loaded.

Just merged commit b77fef61 which fixes this issue when no markup is defined in the settings (thus defaulting to HTML).

But please note that if the markup is changed in the settings, a similar message asking for creating migrations is shown, and this time it creates several new migrations. So I don't think we can consider this issue to be fixed.


Resolving patch:
diff --git a/pootle/apps/virtualfolder/migrations/0001_initial.py b/pootle/apps/virtualfolder/migrations/0001_initial.py
--- a/pootle/apps/virtualfolder/migrations/0001_initial.py
+++ b/pootle/apps/virtualfolder/migrations/0001_initial.py
@@ -21,7 +21,7 @@ class Migration(migrations.Migration):
                 ('filter_rules', models.TextField(help_text='Filtering rules that tell which stores this virtual folder comprises.', verbose_name='Filter')),
                 ('priority', models.FloatField(default=1, help_text='Number specifying importance. Greater priority means it is more important.', verbose_name='Priority')),
                 ('is_browsable', models.BooleanField(default=True, help_text='Whether this virtual folder is active or not.', verbose_name='Is browsable?')),
-                ('description', pootle.core.markup.fields.MarkupField(help_text='Use this to provide more information or instructions. Allowed markup: HTML', verbose_name='Description', blank=True)),
+                ('description', pootle.core.markup.fields.MarkupField(verbose_name='Description', blank=True)),
                 ('units', models.ManyToManyField(related_name='vfolders', to='pootle_store.Unit', db_index=True)),
             ],
             options={
diff --git a/pootle/core/markup/fields.py b/pootle/core/markup/fields.py
--- a/pootle/core/markup/fields.py
+++ b/pootle/core/markup/fields.py
@@ -122,3 +122,8 @@ def formfield(self, **kwargs):
         defaults = {'widget': MarkupTextarea}
         defaults.update(kwargs)
         return super(MarkupField, self).formfield(**defaults)
+
+    def deconstruct(self):
+        name, path, args, kwargs = super(MarkupField, self).deconstruct()
+        kwargs.pop('help_text', None)
+        return name, path, args, kwargs


Test patch: