9👍
Looks like this is not possible.
From the South documentation:
You can do a lot more with this inside a data migration; any model can
be available to you. The only caveat is that you won’t have access to
any custom methods or managers on your models, as they’re not
preserved as part of the freezing process (there’s no way to do this
generally); you’ll have to copy any code you want into the migration
itself. Feel free to make them methods on the Migration class; South
ignores everything apart from forwards and backwards.
4👍
Since Django 1.8, you can include model managers in migrations by adding the use_in_migrations property.
From the docs:
https://docs.djangoproject.com/en/2.0/topics/migrations/#model-managers
class MyManager(models.Manager):
use_in_migrations = True
class MyModel(models.Model):
objects = MyManager()
- Django 1.8: Migrations not detected after deleting migrations folder
- Is it possible, in a django template, to check if an object is contained in a list
- Pip / virtualenv / django installation issue
- EOFError: marshal data too short
2👍
Augmenting @mattdedek’s answer with an example of use in a migration
def my_migration_function(apps, schema_editor):
MyModel = apps.get_model('my_app_name', 'MyModel')
MyModel.objects.create(name='foo')
class Migration(migrations.Migration):
initial = True
dependencies = [
...
]
operations = [
migrations.RunPython(my_migration_function),
]
Currently works in django migrations (tested on version 3.0.4)