-
Notifications
You must be signed in to change notification settings - Fork 66
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
Data migration doesn't write to ParentalManyToManyField #96
Comments
Ran into the same problem. Did the data migration manually outside the migration. |
We are phasing out the one-affiliation-per-incident affiliation model in favor of an Institution model, which can either be applied on a journalist by journalist basis, or to the incident as a whole, but as many as desired. For this, we must move data from the legacy affiliation field to the new Institution field. We do this using a data migration, with two pre- and post- migrations to work around this bug in djang-modelcluster: wagtail/django-modelcluster#96 For the migration, we want these steps: 1. For each incident, examine the `affiliation` field 2. If it null or set to the default value of "Independent," discard it. The "independent" value is a placeholder for no definite affiliation and will not be used in the new scheme. 3. Create, if it doesn't already exist, an Institution with the title of the affiliation. 4. If this incident has any targeted journalists who do not already have an associated institution, associate the new institution with them. 5. If this incident does *not* have any targeted journalists, add the new institution as a target of this incident. This will fully bring any affiliation data into the institution model and apply it to the incidents that this data described.
We are phasing out the one-affiliation-per-incident affiliation model in favor of an Institution model, which can either be applied on a journalist by journalist basis, or to the incident as a whole, but as many as desired. For this, we must move data from the legacy affiliation field to the new Institution field. We do this using a data migration, with two pre- and post- migrations to work around this bug in djang-modelcluster: wagtail/django-modelcluster#96 For the migration, we want these steps: 1. For each incident, examine the `affiliation` field 2. If it null or set to the default value of "Independent," discard it. The "independent" value is a placeholder for no definite affiliation and will not be used in the new scheme. 3. Create, if it doesn't already exist, an Institution with the title of the affiliation. 4. If this incident has any targeted journalists who do not already have an associated institution, associate the new institution with them. 5. If this incident does *not* have any targeted journalists, add the new institution as a target of this incident. This will fully bring any affiliation data into the institution model and apply it to the incidents that this data described.
We are phasing out the one-affiliation-per-incident affiliation model in favor of an Institution model, which can either be applied on a journalist by journalist basis, or to the incident as a whole, but as many as desired. For this, we must move data from the legacy affiliation field to the new Institution field. We do this using a data migration, with two pre- and post- migrations to work around this bug in djang-modelcluster: wagtail/django-modelcluster#96 For the migration, we want these steps: 1. For each incident, examine the `affiliation` field 2. If it null or set to the default value of "Independent," discard it. The "independent" value is a placeholder for no definite affiliation and will not be used in the new scheme. 3. Create, if it doesn't already exist, an Institution with the title of the affiliation. 4. If this incident has any targeted journalists who do not already have an associated institution, associate the new institution with them. 5. If this incident does *not* have any targeted journalists, add the new institution as a target of this incident. This will fully bring any affiliation data into the institution model and apply it to the incidents that this data described.
We are phasing out the one-affiliation-per-incident affiliation model in favor of an Institution model, which can either be applied on a journalist by journalist basis, or to the incident as a whole, but as many as desired. For this, we must move data from the legacy affiliation field to the new Institution field. We do this using a data migration, with two pre- and post- migrations to work around this bug in djang-modelcluster: wagtail/django-modelcluster#96 For the migration, we want these steps: 1. For each incident, examine the `affiliation` field 2. If it null or set to the default value of "Independent," discard it. The "independent" value is a placeholder for no definite affiliation and will not be used in the new scheme. 3. Create, if it doesn't already exist, an Institution with the title of the affiliation. 4. If this incident has any targeted journalists who do not already have an associated institution, associate the new institution with them. 5. If this incident does *not* have any targeted journalists, add the new institution as a target of this incident. This will fully bring any affiliation data into the institution model and apply it to the incidents that this data described.
I also ran into this. The explanation above seems correct; in migrations calling @harrislapiroff I was also able to use your suggested workaround of three migration steps:
Another simpler option that seems to work (using an undocumented API on the field) is to manually invoke for entry in DirectoryEntry.objects.all():
topic_titles = list(entry.topics.values_list('title', flat=True))
entry.temporary_topics.set(
TemporaryTopic.objects.filter(title__in=topic_titles)
)
# This seems to commit the related objects, and doesn't require an entry.save() call.
entry.temporary_topics.commit() |
We are phasing out the one-affiliation-per-incident affiliation model in favor of an Institution model, which can either be applied on a journalist by journalist basis, or to the incident as a whole, but as many as desired. For this, we must move data from the legacy affiliation field to the new Institution field. We do this using a data migration, with two pre- and post- migrations to work around this bug in djang-modelcluster: wagtail/django-modelcluster#96 For the migration, we want these steps: 1. For each incident, examine the `affiliation` field 2. If it null or set to the default value of "Independent," discard it. The "independent" value is a placeholder for no definite affiliation and will not be used in the new scheme. 3. Create, if it doesn't already exist, an Institution with the title of the affiliation. 4. If this incident has any targeted journalists who do not already have an associated institution, associate the new institution with them. 5. If this incident does *not* have any targeted journalists, add the new institution as a target of this incident. This will fully bring any affiliation data into the institution model and apply it to the incidents that this data described.
This should be mentioned in some caveats on a frontpage I guess! :) |
In a perverse coincidence, we had been using the workaround first Perhaps Andy's workaround with calling |
Ran into this issue as well! |
Got around it by creating the new record using the through model instead |
I ran into an issue writing a data migration for a
ParentalManyToManyField
today where the data migration wouldn't write any data to the tables for that field. The migration looked something like this:@gasman suspects the fake model that gets built by django's migration logic doesn't inherit from
ClusterableModel
and is therefore missing some of the logic necessary to make this data migration work.I ended up using a workaround in which I had a migration convert my
ParentalManyToManyField
s to Django's built-inManyToManyField
before the data migration and then another migration afterward to convert them back, which seems to have worked fine.The text was updated successfully, but these errors were encountered: