Django 3.2.9 - Custom User Model not Saving Correctly When Using Bulk Create
I'm working on a personal project and I'm having trouble with saving multiple instances of a custom user model in Django 3.2.9 using `bulk_create()`... I created a custom user model that extends `AbstractBaseUser` and added some additional fields. When I try to save a list of user instances using `bulk_create()`, the instances are created, but the fields that are not part of the default fields (like `date_joined` and `is_active`) are not getting populated correctly. Here's the code I'm using: ```python from django.contrib.auth.models import AbstractBaseUser, BaseUserManager from django.db import models class CustomUserManager(BaseUserManager): def create_user(self, email, password=None, **extra_fields): if not email: raise ValueError('The Email field must be set') email = self.normalize_email(email) user = self.model(email=email, **extra_fields) user.set_password(password) user.save(using=self._db) return user class CustomUser(AbstractBaseUser): email = models.EmailField(unique=True) date_joined = models.DateTimeField(auto_now_add=True) is_active = models.BooleanField(default=True) objects = CustomUserManager() USERNAME_FIELD = 'email' REQUIRED_FIELDS = [] # Bulk create example users = [CustomUser(email=f'user{i}@example.com') for i in range(10)] CustomUser.objects.bulk_create(users) ``` After running this code, I checked the database, and while the users were created, the `date_joined` field remained as `NULL`, and `is_active` was set to `False` instead of the default `True`. I thought `bulk_create()` would respect defaults, but it seems like it's not working as expected for custom fields. I also tried passing `default` values directly in the user instances, like: ```python users = [CustomUser(email=f'user{i}@example.com', date_joined=timezone.now(), is_active=True) for i in range(10)] ``` But this didn't seem to resolve the scenario either. Iβve looked into the Django documentation regarding `bulk_create()` but it doesnβt explain this behavior clearly. Can someone guide to understand why the fields are not saving correctly and how I can fix this? Any advice would be much appreciated.