Install & Compatibility
Where this runs
tested against v1.24.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.272s · 66.5MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 3.5s · import 0.246s · 67MB
66MB installed
● package 66MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
seq
✓ from model_bakery import seq
✗ from model_bakery import baker
timezone
✓ from model_bakery import timezone
✗ from model_bakery import baker
utils
✓ from model_bakery import utils
✗ from model_bakery import baker
This quickstart demonstrates how to use `baker.make()` to create single or multiple Django model instances, specify field values, and use custom generators. For a real application, you would replace `MyModel` with your actual Django model.
from django.db import models
from model_bakery import baker
# Define a simple Django model for demonstration
class MyModel(models.Model):
name = models.CharField(max_length=100)
age = models.IntegerField(default=1)
class Meta:
app_label = 'myapp' # Required for standalone execution without full Django app setup
def __str__(self):
return f"{self.name} ({self.age})"
# Create a single instance of MyModel with default values
instance = baker.make(MyModel)
print(f"Created single instance: {instance}")
# Create multiple instances
instances = baker.make(MyModel, _quantity=3)
print(f"\nCreated {len(instances)} instances:")
for inst in instances:
print(f"- {inst}")
# Create an instance with specific attribute values
specific_instance = baker.make(MyModel, name='Jane Doe', age=25)
print(f"\nCreated specific instance: {specific_instance}")
# Using a custom generator for a field
from model_bakery.generators import gen_integer
custom_age_instance = baker.make(MyModel, age=gen_integer(min_value=40, max_value=50))
print(f"\nCreated custom age instance: {custom_age_instance}")
Debug
Known issues
breakingModel Bakery dropped support for Python 3.8 and 3.9 in v1.21.0, and Django 5.0 and 5.1 in v1.23.0.fixEnsure your project uses Python 3.10+ and Django 5.2+ (or compatible versions for earlier Model Bakery releases). Pin `model-bakery` to an older version if you cannot upgrade Python/Django.
affects: 1.21.0, 1.23.0
gotchaPrior to v1.23.0, using `related()` with ForeignKey relations could inadvertently create duplicate parent entities.fixUpgrade to `model-bakery` v1.23.0 or later to ensure correct handling of related object creation.
affects: <1.23.0
gotchaThe `_bulk_create` flag had known issues with ManyToManyField using custom `through` models (fixed in v1.23.1) and failing to set M2M fields on FK-related objects (fixed in v1.23.4).fixFor reliable bulk creation, especially with M2M fields, upgrade to `model-bakery` v1.23.4 or a newer version.
affects: <1.23.1, <1.23.4
deprecatedThe `seq` utility was moved from `model_bakery.recipe` to `model_bakery.utils`.fixUpdate your import statements from `from model_bakery.recipe import seq` to `from model_bakery.utils import seq`.
affects: 1.22.0
gotchaOverriding `AutoField` values via iterators when using `_quantity` could lead to hangs or unexpected behavior.fixUpgrade to `model-bakery` v1.23.3 or later for correct handling of `AutoField` overrides with `_quantity`.
affects: <1.23.3
Upgrade
Version history
1.24.0latest on PyPI · released Jun 23, 2026
Audit
Dependencies
DjangorequiredCore dependency for any Django project utilizing Model Bakery.