peewee-async icon indicating copy to clipboard operation
peewee-async copied to clipboard

Use of models without primary key?

Open akuzia opened this issue 6 years ago • 1 comments

I have a basic model:

class UserGroup(Model):
    uid = BinaryUUIDField(index=True)
    gid = BinaryUUIDField(index=True)

    class Meta:
        primary_key = False
        indexes = (
            (('uid', 'gid'), True),
        )

When I'm inserting new records:

ug = await create_object(
            UserGroup,
            uid=uid,
            gid=gid
        )

  File "/var/app/app/auth/routes.py", line 101, in group_add_user
    gid=gid
  File "/usr/local/lib/python3.7/site-packages/peewee_async.py", line 458, in create_object
    obj._pk = pk
  File "/usr/local/lib/python3.7/site-packages/peewee.py", line 6426, in _pk
    setattr(self, self._meta.primary_key.name, value)
AttributeError: 'bool' object has no attribute 'name'

Is there a workaround?

akuzia avatar Apr 04 '20 22:04 akuzia

Hello @akuzia, does peewee.CompositeKey work for you?

rudyryk avatar Apr 13 '20 21:04 rudyryk