Visgean Skeloru
Visgean Skeloru

Reputation: 2263

Django reversion fails to recover object after migration

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?

Upvotes: 3

Views: 910

Answers (1)

Visgean Skeloru
Visgean Skeloru

Reputation: 2263

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.

Upvotes: 3

Related Questions