New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use methods like set_parent
during manual RunPython in migrations?
#42
Comments
@jvacek the Alternatively, if your relation is already safe you can just set the If performances are important during the migration you can disable signals and update the tree manually -> |
@jvacek any update? |
We've ended up using the block below, which is quite sub-optimal given that we need to import the model to get access to the functions. We needed to run def migrate_mptt_treenode(apps, schema_editor):
MyModel = apps.get_model("app", "MyModel")
models = MyModel.objects.all()
if models:
for m in models:
if m.parent is not None:
m.tn_parent_id = m.parent.id
m.save()
from project.app.models import MyModel as MyModelButImported
if hasattr(MyModelButImported, "update_tree") and callable(MyModelButImported.update_tree()):
MyModelButImported.update_tree() It would be nice if there was a cleaner way to access the functions during migrations. |
@jvacek Have you any suggestion? |
@jvacek any feedback? |
Python version
3.9.1
Django version
2.2.24
Package version
0.17.0
Current behaviour (bug description)
My model was previously using the MPTT library, and so I'd like to transfer to TreeNode. However I am not really able to do the migration due to the methods not being available when using the
apps.get_model
tactic, and I think directly working on the keys might not be a good idea seeing asset_parent
has things going on.The info about the parent was stored in
parent
before, which is a TreeForeignKey Field from MPTT. I want to first migrate in the new fields from treenode, make the migration, and then remove the inheritance for the MPTTModel after the data is moved.Expected behaviour
I know that
apps.get_model
doesn't make the methods available, so it's not that this should work. Some alternatives for this use-case would be helpful though.The text was updated successfully, but these errors were encountered: