Could this be because you did not have a primary key for your geofeed model
and django automatically used your first column(user) as the primary key
which returns such an error?

On Thu, Oct 27, 2011 at 3:03 AM, Shark <[email protected]> wrote:

> There is problem in this project
> I use Auth User and foreign key in anther table  "geoFeeds" and when
> adding data to table gepFeed am error happened
>
> column user_id is not unique
>
> when changing the userId it add one time but the second time it fails
> and give this error I don't know why
>
> this is the code
>
> models.py
>
> from django.db import models
> from django.contrib.auth.models import User
>
> class GeoFeed(models.Model):
>    user = models.ForeignKey(User, unique=False)
>    link = models.URLField()
>    name = models.CharField(max_length=100)
>    def __unicode__(self):
>        return self.id
>
>
> and this is the function that add feeds in view
>
>
>
> def addFeed(request):
>    ok = False
>
>    if request.method == 'POST': # if the form has been submitted
>        fname = request.POST.get('fname', '') # feed name
>        flink = request.POST.get('flink', '') # feed link
>
>        if fname is not None and flink is not None:
>            # save
>            u = User.objects.get(pk = 2) # pre-defined user till amr
> finishes user-sys
>            f = GeoFeed(user = u, link = flink, name = fname)
>            f.save()
>
>    return render_to_response('add_feed.html', {'ok': ok},
> RequestContext(request))
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to