3

I have this model:

from django.contrib.auth.models import User
from django.db import models
import reversion


@reversion.register()
class BlogPost(models.Model):
    author = models.ForeignKey(User)
    title = models.CharField(max_length=32)
    content = models.TextField()

Now I decided to add this field to the model:

random_field = models.PositiveIntegerField(null=False, blank=False)

I created migrations and choose default value:

operations = [
    migrations.AddField(
        model_name='blogpost',
        name='random_field',
        field=models.PositiveIntegerField(default=10),
        preserve_default=False,
    ),
]

And migrate it.

Now, I am using Django admin with reversion support, I modified the blog post few times before the migration and now I want to migrate to the version that did not have the random field. It says:

Could not save BlogPost object version - missing dependency.

Is there a way how to prevent this? I think its because the migration did not create the revision. Seems like the error is somewhere here: reversion/models.py#L21

I am using

Django==1.11.1
django-reversion==2.0.8

with sqlite db.

Is there a way to prevent this?

Visgean Skeloru
  • 2,237
  • 1
  • 24
  • 33

1 Answers1

3

As per GH issue:

Ah, I see. annoying. It appears that the revisions can handle deleting a field, but not adding one.

Automating this is pretty much impossible. There are revision databases out there with gigbytes of old revisions, and updating old revision data when a new migration occurs could take days of runtime per migration. It's not really feasible.

My general approach is to delete the revision data after a migration. If you really want to keep it, then you can write your own data migration the in the app.

-- Author of the project.

So it seems that reverting after migrating is simply not supported and while it may work sometimes its not meant to be used that way.

Visgean Skeloru
  • 2,237
  • 1
  • 24
  • 33