So, if I interpret your problem correctly, you have an old Model ( Profile
), and you are trying to replace it with a new SurveyProfile
model. Given the circumstances, you might consider using a database migration tool such as South in the long run. At the moment, you can run the script in the Django shell ( manage.py shell
):
from yourappname.models import * for profile in Profile.objects.all(): survey_profile = SurveyProfile()
Use of the south
If this project needs to be maintained and updated in the long term, I highly recommend using a database migration package, such as South , which will allow you to change the fields in the model and transfer your database painlessly.
For example, you assume there were too many ManyToManyField
in your original model. With the South, you:
- Remove fields from the model.
- Automatically create schema migration.
- Apply migration.
This allows you to reuse all of your old code without changing the model names or deleting with the database.
source share