RunPython migrations are broken with VersionedForeignKey fields
I'm trying to write a data migration for my app, and receiving the "not a Versionable" error when I read any VersionedForeignKey fields from models retrieved with the apps.get_model() recommended in Django docs. For example, this code is inside a RunPython migration:
Thing = apps.get_model('myapp', 'Thing')
mything = Thing.objects.current.first()
thing.vfk_field # throws TypeError("It seems ...")
I'm not sure whether this is the fault of Django migrations or of CleanerVersion.
I set a breakpoint inside versions/models.py at line 619 and I find that my target objects have made-up types:
(Pdb) type(current_elt).mro()
[<class 'Color'>, <class 'django.db.models.base.Model'>, <type 'object'>]
(Pdb) apps.get_model('rms', 'color').mro()
[<class 'rms.models.Color'>, <class 'versions.models.Versionable'>, <class 'rms.models.Term'>, <class 'django.db.models.base.Model'>, <type 'object'>]
Additionally, in this context there is no Model.objects.current and no Model.objects.as_of because objects is not a VersionedManager.
I don't know what the right thing to do is here. In my project, I can avoid writing a data migration today but I will probably need one later.
Did you find any way around this?
I don't think so; I've moved on to other projects and as far as I can remember, I just avoided doing a proper data migration on that project.
Thanks @ezheidtmann And I have just gone with a manual way - using relation ids, not related instances themselves.