{"id":3000,"library":"model-bakery","title":"Model Bakery","description":"Model Bakery is a smart object creation facility for Django, designed to simplify the creation of test data and mock objects for your Django models. It is currently at version 1.23.4 and maintains an active development cycle with frequent patch and minor releases, ensuring support for recent Django and Python versions.","status":"active","version":"1.23.4","language":"en","source_language":"en","source_url":"https://github.com/model-bakers/model_bakery","tags":["django","testing","fixtures","factory","orm","test-data"],"install":[{"cmd":"pip install model-bakery","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core dependency for any Django project utilizing Model Bakery.","package":"Django","optional":false}],"imports":[{"symbol":"baker","correct":"from model_bakery import baker"},{"symbol":"Recipe","correct":"from model_bakery.recipe import Recipe"},{"note":"The 'seq' utility was moved from recipe to utils in v1.22.0.","wrong":"from model_bakery.recipe import seq","symbol":"seq","correct":"from model_bakery.utils import seq"}],"quickstart":{"code":"from django.db import models\nfrom model_bakery import baker\n\n# Define a simple Django model for demonstration\nclass MyModel(models.Model):\n    name = models.CharField(max_length=100)\n    age = models.IntegerField(default=1)\n\n    class Meta:\n        app_label = 'myapp' # Required for standalone execution without full Django app setup\n\n    def __str__(self):\n        return f\"{self.name} ({self.age})\"\n\n# Create a single instance of MyModel with default values\ninstance = baker.make(MyModel)\nprint(f\"Created single instance: {instance}\")\n\n# Create multiple instances\ninstances = baker.make(MyModel, _quantity=3)\nprint(f\"\\nCreated {len(instances)} instances:\")\nfor inst in instances:\n    print(f\"- {inst}\")\n\n# Create an instance with specific attribute values\nspecific_instance = baker.make(MyModel, name='Jane Doe', age=25)\nprint(f\"\\nCreated specific instance: {specific_instance}\")\n\n# Using a custom generator for a field\nfrom model_bakery.generators import gen_integer\ncustom_age_instance = baker.make(MyModel, age=gen_integer(min_value=40, max_value=50))\nprint(f\"\\nCreated custom age instance: {custom_age_instance}\")","lang":"python","description":"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."},"warnings":[{"fix":"Ensure 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.","message":"Model 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.","severity":"breaking","affected_versions":"1.21.0, 1.23.0"},{"fix":"Upgrade to `model-bakery` v1.23.0 or later to ensure correct handling of related object creation.","message":"Prior to v1.23.0, using `related()` with ForeignKey relations could inadvertently create duplicate parent entities.","severity":"gotcha","affected_versions":"<1.23.0"},{"fix":"For reliable bulk creation, especially with M2M fields, upgrade to `model-bakery` v1.23.4 or a newer version.","message":"The `_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).","severity":"gotcha","affected_versions":"<1.23.1, <1.23.4"},{"fix":"Update your import statements from `from model_bakery.recipe import seq` to `from model_bakery.utils import seq`.","message":"The `seq` utility was moved from `model_bakery.recipe` to `model_bakery.utils`.","severity":"deprecated","affected_versions":"1.22.0"},{"fix":"Upgrade to `model-bakery` v1.23.3 or later for correct handling of `AutoField` overrides with `_quantity`.","message":"Overriding `AutoField` values via iterators when using `_quantity` could lead to hangs or unexpected behavior.","severity":"gotcha","affected_versions":"<1.23.3"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}