[英]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. 现在,我正在使用Django管理员和reversion支持,我在迁移之前几次修改了博客文章,现在我想迁移到没有随机字段的版本。 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
似乎错误就在这里: reversion / models.py#L21
I am using 我在用
Django==1.11.1
django-reversion==2.0.8
with sqlite db. 用sqlite db。
Is there a way to prevent this? 有办法防止这种情况吗?
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. 因此,迁移后的恢复似乎根本不受支持,虽然它可能有效但有时并不意味着以这种方式使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.