Dear Cictani: Thank you for your suggestion. But how I write the script? I mean do I need to write another py file in my project? And still, how do I deal with the database of stoichiometrymeta class? Since there is no table corresponding to this class in my database, so I think I can't run the project successfully. Thank you for your patience to help me out and I am sorry to trouble you again. I am really new to Django so I have to admit that I have a lot to learn and sometimes I may ask some stupid questions....if you can suggest some tutorials or materials to learn that would be also great! Thank you again for your help!!!! I am really appreciate that.
在 2018年3月24日星期六 UTC+1下午1:16:21,Cictani写道: > > After adding the new model and doing the migration you have to write a > small script which will convert the data. You have to go through all the > Reactionsmeta objects with > > for reaction in Reactionsmeta.objects.all(): > > Then within the for loop you have to create another for loop which will go > through all metabolite columns from 1 to 6: > > for i in range(1, 7): > > Then you would have to check if the column is not None: > > current_metabolite = getattr(reaction, 'metabolite' + i, None) > current_stoichiometry = getattr(reaction, 'stoichimetry' + i, None) > if current_metabolite is not None and current_stoichiomentry is not None: > > If current_metabolite is not none you can add a new StoichiometryMetabolite > object: > > StoichiometryMetabolite.objects.create(metabolite=current_metabolite, > stoichiometry=current_stoichiomentry, reaction=reaction) > > > That' basically it. You should probably also write a test which makes sure > that all data has successfully converted. If everything worked fine and all > views, templates etc have been updated you can remove the old fields from > the model. > > > > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ae273a05-bb6f-41fc-a076-68ef4fff1075%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.