On 2/13/07, vinjvinj <[EMAIL PROTECTED]> wrote:
>
>
> Found the answer:
>
> # a function to create primary key ids
> i = 0
> def mydefault():
>     global i
>     i += 1
>     return i


This counter is going to start over every time you run your program. The
second time you run it, it's going to start creating IDs that already exist,
so it'll fail. Most databases have built-in support for this kind of thing
(via autoincrement and serial types), and you should almost certainly use
those features instead.

t = Table("mytable", meta,
>     # function-based default
>     Column('id', Integer, primary_key=True, default=mydefault),
>
>     # a scalar default
>     Column('key', String(10), default="default")
> )
>
> Thanks,
>
> VJ
>
> On Feb 13, 1:18 pm, "vinjvinj" <[EMAIL PROTECTED]> wrote:
> > I use the mx.UID package to generate all my keys. Is there any way to
> > specify that this function be called to generate the primary key for
> > inserts?
> >
> > Thanks,
> >
> > VJ
>
> On Feb 13, 1:18 pm, "vinjvinj" <[EMAIL PROTECTED]> wrote:
> > I use the mx.UID package to generate all my keys. Is there any way to
> > specify that this function be called to generate the primary key for
> > inserts?
> >
> > Thanks,
> >
> > VJ
>
>
> >
>

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

Reply via email to