You are passing a uuid, not a uuid function therefore it is always the
same value:

try replace

default=uuid.uuid4()

with

default=uuid.uuid4
or
default=lambda:uuid.uuid4()
or
default=lambda:str(uuid.uuid4())

they should all work.

On Apr 15, 2:20 am, Johann Spies <johann.sp...@gmail.com> wrote:
> Please help me to understand how to use uuid.
>
>  db.define_table('x',
>                 Field('uuid', length=64, default=uuid.uuid4(), notnull=True,
>                       writable=False, unique=True, ondelete='CASCADE'),
>                 Field('a'),
>                 Field('b'))
>
> In [4]: db.x[0] = dict(a='a', b= 'b')
>
> In [5]: db.commit()
>
> In [6]: db.x[0] = dict(a='d', b= 'c')
> ---------------------------------------------------------------------------
> IntegrityError                            Traceback (most recent call last)
> ....
> some traceback code
> ...
> IntegrityError: duplicate key value violates unique constraint "x_uuid_key"
>
> How did I use uiid wrongly?  I thought it was supposed to be a unique field.
>
> Regards
> Johann
>
> --
>  May grace and peace be yours in abundance through the full knowledge of God
> and of Jesus our Lord!  His divine power has given us everything we need for
> life and godliness through the full knowledge of the one who called us by
> his own glory and excellence.
>                                                     2 Pet. 1:2b,3a

Reply via email to