sqlite3 - IntegrityError in django mptt - column not unique -
I have a problem saving a form in the Django app. I will call a model called 'Model' by the name 'Dataset'. I want to create a model called 'Image', both of which are MPT models.
Model
Class Image (MPTT Model): Name = Model. Defiled (max_length = 50, exclusive = true) parent = TreeForeignKey ('self', null = true, empty = true, related_name = 'children') DEF __unicode __ (self): return self.name class dataset (MPTTModel) : Name = models.CharField (MAX_LENGTH = 50, unique = true) image = TreeForeignKey (image, void = true, empty = true, unique = true, related_name = 'image') def __unicode __ (self): back self Name class MPTTMeta: parent_attr = 'image'
When I try to save a dataset, I get a integrity error:
IntegrityError At / associate / column image_id is not unique Request method: Get Request URL: http://127.0.0.1:8000/Assistant / Django version: 1.6.2 Exception type: IntegrityError exception value: column image_id is not unique exception location: Executed in C: \ Python27 \ lib \ site-package \ Django \ db \ backend \ sqlite3 \ base.py, line 450
views.py
D F. Index (requests): images = Image.objects.all () Dataset = [] For images in i: if i.rank ()> = 3: dataset = dataset (image = i, name = i.name) dataset .save () Dataset. Append Return (Request, 'Associate / Index.html', '' Datasets '': Datasets)) Learn Less (Request): If request.method == 'POST': Try : Dataset = Request POST.get ('dataset', incorrect) Model = dataset.objects .get (name = dataset) Model: print model.Name Second: Exclude the dataset and print "No Model". DoNotExist: Return render (request, 'affiliate / index') Other: return render (request, 'partner / learn', {'dataset': model})
< Div class = "post-text" itemprop = "text">
You have unique = true in your dataset Model for image field means that you can not specify an image in different dataset frequencies. But you are doing it in your index every time you try to create a new dataset for every image in your index but if the dataset with this image is already created - you will get this 'column image_id not unique' error . Please review your application logic and remove either unique = True or rewrite the behavior.
Comments
Post a Comment