When I create factory_boy objects, the object does not have a primary key, and I'm not sure why. Here is my model and factory:
# models.py from django.db import models from django.contrib.auth.models import User class UserProfile(models.Model):
Now, according to the factory_boy documentation on associations, if I create a user instance, I should get the id field. However, I do not. This is what I get (in the interpreter):
>>> from app.factories import UserFactory, UserProfileFactory >>> user = UserFactory() >>> user.username
Similarly:
>>> user_profile = UserProfileFactory() >>> user_profile.gender
The documentation states that these user.id and user_profile.id commands should return “False” instead of “True”, since I am creating factory_boy instances (as opposed to assembly). What am I missing here? Why am I not getting the id value when I create these instances? It seems that the only way to get the identifier is to explicitly create the id attribute in my factories. However, I don’t see this in the documentation, so I don’t think what you should do.
Thanks.
source share