Column user_id is not Unique #113
Comments
As far as i read, there is nothing wrong with your code. I'll mark this as a bug. I believe it has something to do with OneToOneField, but i'll take a closer look. Thanks for the report. =) |
I have a follow-up. When I try to mock the UserProfile model, I have the same problem.
IntegrityError: column user_id is not unique |
which Django and model_mommy versions are you using? |
Django==1.4.5 |
does this bug also happens with the latest? (master branch) |
Am I doing it wrong? pip install -e git+https://github.com/vandersonmota/model_mommy.git@f734decb017e537b42993ceb95768f489971b267#egg=model_mommy-dev
|
the correct import is from model_mommy.recipe import Recipe |
Sure! I've pasted the wrong line... The result is the same n [1]: from model_mommy.recipe import Recipe ImportError Traceback (most recent call last) /Users/fguimara/.virtualenvs/twist-integrator/src/model-mommy/model_mommy/recipe.py in () /Users/fguimara/.virtualenvs/twist-integrator/src/model-mommy/model_mommy/mommy.py in () ImportError: cannot import name Sequence |
Sorry, just pushed the fix. Try it again. thanks! |
So, for and Django==1.4.6 The error persists: (...) (...) IntegrityError: column user_id is not unique |
I created a UserProfile model here pointing (OneToOne) to django.contrib.auth.User and i didn't got this error. This also happens if you try to create the UserProfile without model_mommy? |
Hi, I've got a similar problem, we have a post_save hook that creates a user profile as soon as a user is created. So, then when model_mommy is to generate a user profile, it first correctly generates the user instance but then the user profile is automatically created by the post_save hook, so then when mommy tries to create the user profile with oneToOne field to the already created user, it gets a unique key error because the User profile has already been created. I have a fix for this, I am about to create a pull request. |
…rom a related field or by some other means, it might throw an unique exception when it is created again in Mommy.instance(). The exception is thrown if the to-be created instance has OneToOneField or some other field that is set (in **attrs) and is unique.
@tkrajca's fix works for me :) Thanks. |
I have the following models
app1.models.py
class UserProfile(Subject):
"""
UserProfile class
"""
# This field is required.
user = models.OneToOneField(User)
# Other fields here
company = models.CharField(max_length=50, null=True, blank=True,
verbose_name=("Company"))
contact = models.CharField(max_length=50, null=True, blank=True,
verbose_name=("Contact"))
msg = models.TextField(null=True, blank=True, verbose_name=_("Message"))
class ParentImportJob(models.Model):
"""
Class to store importing jobs
"""
app2.models.py
class ImportJob(ParentImportJob):
"""
Class to store jobs of files being imported
Extends ParentImportJob
ParentImportJob is not abstract! But I am interested in 2 separated tables
"""
The following recipe:
ob_mock = Recipe(ImportJob,
import_file=ofile.read(),
import_result=EXCEL_DICT)
When I ran self.job = mommy.make_recipe('excel2db.job_mock') inside the testcase I get IntegrityError: column user_id is not unique
I'm doing something wrong?
The text was updated successfully, but these errors were encountered: