Skip to content
This repository has been archived by the owner on Jan 24, 2018. It is now read-only.

PrimaryKey is expected to be *an integer managed by the db* (rowid) #31

Open
e3krisztian opened this issue Mar 23, 2015 · 1 comment
Open

Comments

@e3krisztian
Copy link

This is mostly a documentation issue/caveat, important mostly because of the surprises on first use.
I expect this limitation to be a yet undocumented(?) design decision.

If there is no PrimaryKey defined, then an id field is implicitly expected to exist and is treated like a primary key, this implies, that it has to be defined in the database. (It is actually documented, yet surprising).

However some important existing tables do not have such a primary key field.

E.g. sqlite's sqlite_master table has none defined explicitly, we can only assume a composite key of (type, name).

class SQLiteMaster(Model):

    table_name = 'sqlite_master'
    type = PrimaryKey()
    name = PrimaryKey()
    # skylark keeps track only of the last PrimaryKey, but it looks correct
    # the important bit: need to define at least one PK
    #     otherwise skylark requires `id` to exist


def table_exists(table_name):
    return SQLiteMaster.findone(type='table', name=table_name) is not None

When I have attempted to use UUID-s as primary keys (i.e. a string), the in-memory uuid field has been silently overwritten by a short integer (rowid)!

@hit9
Copy link
Owner

hit9 commented Mar 28, 2015

Hi, at first , this orm is long time no maintained, and there's no plan for forward development, the second, skylark is only designed for tables with primary keys.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants