Re: Exception Value: column user_id is not unique
Did you have unique=True when you created the database with south? If not, I cannot any reason for the discrepancy you are describing. south does treat apps that have migrations separately from the rest, but that doesn't seem to be related to the issue you had.
On Tuesday, November 19, 2013 7:59:58 PM UTC-5, HannesP wrote:
-- On Tuesday, November 19, 2013 7:59:58 PM UTC-5, HannesP wrote:
Thanks for tip tim.
Actually I have noticed a weird thing. Hope you can explain why it happened:
Initially, I had installed south. when I created a fresh sqlite database, the module that I created always came separate form others. That is .manage.py syncdb resulted in
Not synced (use migrations):
- userpics
Then after migrate the database was created.
Then I disabled south module and started with a fresh database (with unique=False in the model) and I saw taht the error is gone. Now I can upload multiple images. How is it so? What could be wrong with the module that south treated it separately?
Thanks,
Hannes
On Wednesday, November 20, 2013 1:36:14 AM UTC+1, tim wrote:If you first run syncdb with the UserPic.user field unique=True, it's not enough just to change unique=False. You'll also need to remove the database unique constraint. Do you have the problem on a fresh syncdb if unique=False? If so, it would be helpful to include the full traceback of the error.
On Tuesday, November 19, 2013 4:34:35 PM UTC-5, HannesP wrote:I'm Django noob so please bear with me. I am trying to make a simple gallery for usres so that they can upload pics to their profile. Here are the relevant parts:
models.py
def get_uplaod_file_name(instance,
filename ): return 'uploaded_files/%s_%s' % (str(time()).replace('.','_'), filename) class UserPic(models.Model): user = models.ForeignKey(User, unique=False) picfile = models.FileField(upload_to=get_uplaod_file_name ) @models.permalink def get_absolute_url(self): return ('view_pirate', None, {'user': self.account.user}) def __unicode__(self): return unicode(self.picfile.name)views.py
@login_required def list(request): # Handle file upload if request.method == 'POST': picform = PicForm(request.POST, request.FILES) if picform.is_valid(): newpic = UserPic(picfile = request.FILES['picfile']) newpic = picform.save(commit=False) newpic.user = request.user newpic.save() message = "file %s is uploaded" % newpic userpics = UserPic.objects.all() return render_to_response('userpics/
listpics.html' , {'userpics': userpics, 'picform': picform}, context_instance=RequestContext (request) ) else: picform = PicForm() # A empty, unbound form userpics = UserPic.objects.all() return render_to_response( 'userpics/listpics.html', {'userpics': userpics, 'picform': picform}, context_instance=RequestContext (request) )The app works fine for one image upload but the problem is that whenever a user tries to upload a second image, Django gives this error:
column user_id is not unique
I have also tried 'unique= True on a fresh database in the model, but still got stocked at this problem. Appreciate your hints.
Thanks
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7496f26a-d19e-4dbf-a365-f77092fadd4d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home