Thanks Anthony for your reply.

The table already have an old data so i can't remove the column id or
change in the database structure.

Is there another solution in controller level not database level?

Thanks in Advance

On Apr 4, 2:54 pm, Anthony <[email protected]> wrote:
> Your table already includes an 'id' field by default, which is an
> auto-increment integer field starting at 1. Why do you need a separate
> 'membership_id' field? If it's a legacy database and you need the name of
> the 'id' field to be 'membership_id', you can simply define the field type
> as 'id' (seehttp://web2py.com/book/default/chapter/06?search=auto-increment
> ).
>
> Also, you should use Field() instead of SQLField() -- they're both the same,
> but the latter has been deprecated in favor of the former.
>
> Anthony
>
> On Monday, April 4, 2011 8:35:00 AM UTC-4, Neveen Adel wrote:
> > Hello,
>
> > I have the following table:
>
> >  db.define_table("member",
> >       SQLField("membership_id", "integer",notnull=True),
> >       SQLField("first_name", "string", notnull=True)
> > )
>
> > and i want  the membership id to be incremented automatically.
>
> > the way i used :
>
> >  every time i inserted it , i select the max membership_id and adding
> > one on its value as:
>
> >   result=db.executesql("select max(membership_id) from member")
> >   record=result[0]
> >   if record[0]:
> >     next_membership_id = record[0]+1
> >   else:
> >      next_membership_id=1
> >    form.vars.membership_id=next_membership_id
>
> > But this solution allows duplicates??
>
> > could anyone tell me  what is the perfect solution?
>
> > Thanks in Advance

Reply via email to