I want to migrate from one Model to another model with extra field. I tried with both iterative and free fall - but none of those work. Whenever I run beanie migrate -uri <connection-string> -db <db-name> -p <path/to/*_migrate.py> --distance 1 --forward
, it just shows:
Building migration list
The following code is similar to my actual code:
from beanie import Document, free_fall_migration
class OldModel(Document):
name: str
class NewModel(Document):
name: str
new_field: str
class Forward:
@free_fall_migration(document_models=[OldModel, NewModel])
async def add_new_field(self, session):
async for old_data in OldModel.find_all():
new_data = NewModel(
**old_data .dict(),
new_field='yay'
)
await new_data.replace(session=session)
class Backward:
@free_fall_migration(document_models=[OldModel, NewModel])
async def remove_new_field(self, session):
async for new_data in NewModel.find_all():
new_data_dict = new_data.dict()
new_data_dict.pop('new_field')
old_data = OldModel(
**new_data_dict
)
await old_data.replace(session=session)
Am I missing something?
Current Environment:
- OS: Windows 11
- Python Version: 3.9.x
- Beanie Version: 1.18.0b
- MongoDB Version: 5