isar / isar/hive

HiveError (HiveError: The same instance of an HiveObject cannot be stored with two different keys

Open
#1,047 5 comments 2 reactions 0 assignees View on GitHub
problem
Dominant language
Dart
Stars
4.4k
Forks
449
PR merge metrics
No merged PRs in 30d

Description

**Steps to Reproduce**
I've added an hive object to my Flutter Project. When I use it with provider and create some object and put.

Getting Error: `HiveError (HiveError: The same instance of an HiveObject cannot be stored with two different keys ("0" and "1").)
`

**Code sample**
```
import 'package:hive/hive.dart';

part 'book.g.dart';

@HiveType(typeId: 7)
class Book extends HiveObject {
Book({
required this.orderNo,
required this.name,
required this.author,
required this.fileName,
required this.img,
required this.lastPage,
required this.lastOpen,
});

@HiveField(0)
int orderNo;

@HiveField(1)
String name;

@HiveField(2)
String author;

@HiveField(3)
String fileName;

@HiveField(4)
String img;

@HiveField(5)
double lastPage;

@HiveField(6)
int lastOpen;
}

```

I know the last page looks weird by actually I am save it as `scroll controller offset`
and I know that lastOpen should string or date format, I use epoch format like 164112312334

**Version**
- Platform: iOS
- Flutter version: [3.0.5]
- Hive Flutter version: [1.1.0]

Contributor guide

No contributing guide indexed for this repository

Research direction

The report names no repository files or tests. Reproduce the sample with Hive Flutter 1.1.0 and Flutter 3.0.5, then trace how the same HiveObject receives keys during storage. Done means identifying the cause of the conflicting keys and documenting a verified resolution or a clearly scoped code change.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
databases, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.