objectbox / objectbox-dart

Flutter database for super-fast Dart object persistence
https://docs.objectbox.io/getting-started
Apache License 2.0
981 stars 119 forks source link

I/flutter ( 8179): Invalid argument(s): object put failed: 10002 ID is higher or equal to internal ID sequence: 8 (vs. 1). Use ID 0 (zero) to insert new entities. #250

Closed ranomoh closed 3 years ago

ranomoh commented 3 years ago

when we put(add) new objects from remote db, it failed if thier ids are bigger numbers and the older objects with smaller ids was deleted say we have deleted documents with ids from 1to7 in the device(mobile in my case), if we try to put documents from remote(server) database with ids 8, 9, 10... we get error: I/flutter ( 8179): Invalid argument(s): object put failed: 10002 ID is higher or equal to internal ID sequence: 8 (vs. 1). Use ID 0 (zero) to insert new entities.

Basic info:

Code

Logs, stack traces

I/flutter ( 8179): Invalid argument(s): object put failed: 10002 ID is higher or equal to internal ID sequence: 8 (vs. 1). Use ID 0 (zero) to insert new entities.

Additional context

vaind commented 3 years ago

Have you considered https://docs.objectbox.io/advanced/object-ids#self-assigned-object-ids ?

ranomoh commented 3 years ago

hello vaind, as they mentioned in the documentation: Warning: self-assigned IDs break automatic state detection (new vs. persisted entity based on the ID). Therefore, you should put entities with self-assigned IDs immediately and may have to attach the box manually, especially when working with relations. i searched in google, and I found that some ppl have issues when they try to assign ids by their self (the relationships not working). could you show me how to add: @Id(assignable = true)in dart file, coz i get: Undefined name 'assignable'.

vaind commented 3 years ago

in Dart, the syntax is @Id(assignable: true)

Yes, in case you use custom IDs you have to take greater care with relations, as with any other DB.

AGenius commented 3 years ago

Personally, where I have data from the server that has an ID I will need I just have an additional field called realID and I am letting objectbox (I used ActiveAndroid in the same way in the old version of my app that I am re-writing)

vaind commented 3 years ago

From the lack of a followup it looks like the question was answered.