Writing Data Migrations in Django

preview_player
Показать описание
When you migrate models sometimes you need to modify the data, but that can sometimes be difficult. Fortunately Django has built-in support for migrations now, which also means data migrations. Using data migrations you can modify the data anyway you need to to fit your new models.
Рекомендации по теме
Комментарии
Автор

It is awesome exactly what I need. Thank you very much.

RuslanSkiraUkraine
Автор

I was looking for some more information on the schema_editor parameter, actually. I'm actually trying to write a data migration, which uses the schame_editor to change a foreign_key destination model and repopulating those relationships columns with a value based on the old ones.
According to the django docs, schema_editor.alter_field is supposed to do that, and this function receives 3 parameters: model, old_field and new_field. However, I did not find the data types of old_field and new_field detailed anywhere in the django project documentation...anyone has any clues or leads on that matter? Any help would be appreciated (I'm trying to look for code examples that use this function, but could'nt find them anywhere yet)

BrRznd