tag_model uninitialized in migrations
See original GitHub issueI’m trying to migrate django-tagging to django-taggit. After having run a migration to add it side-by-side such that it looks like this:
class Flow(models.Model):
tags = TagField()
new_tags = TaggableManager()
I was trying to copy over the tags:
def transfer_tags(apps, schema_editor):
Flow = apps.get_model("flow", "Flow")
for f in Flow.objects.all():
if f.tags:
f.new_tags.add(*f.tags.split(" "))
f.save()
class Migration(migrations.Migration):
dependencies = [
('flow', '0003_flow_new_tags'),
]
operations = [
migrations.RunPython(transfer_tags),
]
But this ran into an AttributeError when running ‘migrate’:
> ~/env/local/lib/python2.7/site-packages/taggit/managers.py(192)_to_tag_model_instances()
190 for t in tags:
191 import ipdb;ipdb.set_trace()
--> 192 if isinstance(t, self.through.tag_model()):
193 tag_objs.add(t)
194 elif isinstance(t, six.string_types):
ipdb> self.through
<class 'TaggedItem'>
And when I continue, I am getting this error:
AttributeError: type object 'TaggedItem' has no attribute 'tag_model'
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:9 (2 by maintainers)
Top Results From Across the Web
https://stackoverflow.com/questions/63778063/tag-m...
No information is available for this page.
Read more >Rails 6 Has and Belongs To Many Gotchas - codingpackets.com
For my examples I am using a direct relationship between two models. This utilizes a join table to join the models together. Relationship...
Read more >rake db:migrate -> uninitialized constant - Google Groups
Hi--. I'm trying to do a first migration (2.3.5). I generated a model "Video", but when I try to migrate I get "uninitialized...
Read more >galaxy.managers.collections — Galaxy Project 22.05.1 documentation
UNINITIALIZED_ELEMENT elif not has_structure: collection_type_description ... be coming in as a dictionary of tag model objects if copying them from other ...
Read more >Migration Error: NameError: uninitialized constant ... - GitHub
Ruby 2.5.3 Rails 4.2.10 When doing a migration I get this error: NameError: uninitialized constant AddRegActionIDToKeywordBatches Pretty ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I added this snipped to my data migration and it seemed to work well. Might be nice to generalize it and add a helper utility somewhere.
@steverecio What do you do with the
tagged_items
after this though? I’m trying to get this to work with a data migration as well, and trying to save the TaggedItem back tomymodel
is not working, and still giving me the same error.