I have a Django model (called BiomSearchJob
) which is currently live and I want to add a new many-to-many relation to make the system more customizable for the user. Previously, users can submit a job without specifying a set of TaxonomyLevelChoices
but to add more features to the system, users should now be able to select their own taxonomy levels.
Here's the model:
class TaxonomyLevelChoice(models.Model):
taxon_level = models.CharField(
verbose_name="Taxonomy Chart Level", max_length=60)
taxon_level_proper_name = models.CharField(max_length=60)
def __unicode__(self):
return self.taxon_level_proper_name
class BiomSearchJob(models.Model):
...
# The new many-to-many relation
taxonomy_levels = models.ManyToManyField(
'TaxonomyLevelChoice', blank=False, max_length=3,
default=["phylum", "class", "genus"])
name = models.CharField(
null=False, blank=False, max_length=100, default="Unnamed Job",
validators=[alphanumeric_spaces])
...
Currently, all existing BiomSearchJobs
implicitly have the three taxonomy levels listed in the default=
term (which are not user-selectable) and hence are all the same in the database. After running migrate
, I find that the previous jobs don't immediately have the three taxonomy level relations, they only return an empty set upon calling job.taxonomy_levels.all()
(if job
were an instance of BiomSearchJob
).
Is there a way to retroactively add this relationship without manually going through everything? Ideally, by just running migrate
I would like the existing BiomSearchJobs
to have phylum
, class
, and genus
listed in the taxonomy_levels
attribute.