Skip to content

unique-parameter only partly taken into account #2

@eeas-joas

Description

@eeas-joas

Hello,
it seems, that the unique-parameter is only taken into during the runtime of the script, but not respecting already written values.

See the following code-snippet, when running the first-time, the database is created and the values are written. When running it the second time, the values are appended, but the user_id-unique-value is not respected, so the user-ids are duplicated without any exception..

Is this a known behaviour?

Thanks,
best regards,
Josef

from tinydb import TinyDB, Query
from tinydb_constraint import ConstraintTable
from tinydb_constraint import Constraint

TinyDB.table_class = ConstraintTable
db = TinyDB('db.json')

db.set_schema({'user_id': Constraint(type_=int, unique=True, not_null=True)})
db.insert({'user_id':1,'par':"val1"})
db.insert({'user_id':2,'par':"val2"})
db.insert({'user_id':3,'par':"val3"})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions