HiveError: Cannot read, unknown typeId: 34. Did you forget to register an adapter? when Removing an Adapter
Steps to Reproduce
- Create custom Adapter MainClass, create custom Adapter Property which is a property of A. Register
- Write data
- Remove adapter B
- Read old data.
Reading fails with message HiveError: Cannot read, unknown typeId: 34. Did you forget to register an adapter?
Based on the docs, reading old data after removing a property should be safe, but it throws
Found another possible solution in this comment
But we added Hive.ignoreTypeId(N) and now the error has changed, but it is still failing
The new error is RangeError: Not enough bytes available.
Code sample
// Initialization
Future<void> initializeHive() async {
await Hive.initFlutter();
Hive.registerAdapter(MainClassAdapter());
Hive.registerAdapter(PropertyAdapter());
...
}
// Classes definition
@HiveType(typeId: 1)
class MainClass {
MainClass({
required this.property,
});
...
@HiveField(N)
final Property property;
@HiveType(typeId: 2)
class Property {
Property({required this.name});
@HiveField(0)
final String name;
}
// After writing some data with this structure,
// we removed Property from the registerAdapter calls, and form the MainClass definition
But we started getting HiveError: unknown typeId when reading old data
// Then, we tried with
// Initialization
Future<void> initializeHive() async {
await Hive.initFlutter();
Hive.registerAdapter(MainClassAdapter());
Hive.ignoreTypeId(2);
...
}
// But now we get RangeError: Not enough bytes available.
Version
- Platform: iOS, Android
- Flutter version: 3.7.0
- Hive version: hive: 2.2.3, hive_flutter: 1.1.0, hive_generator: 2.0.0
I think you should add adapterName like that
Could you elaborate on the need for that extra parameter for a solution here? It seems that if not set a default one is created, that is already unique to each adapter
Same here, i faced this after upgrading flutter 3.10.2
Any update on this?!
deleteFromDisk() and open again
Try add ignoreTypeId before registerAdapter
Hive.ignoreTypeId(2);
Hive.registerAdapter(MainClassAdapter());
I'm also facing this issue with Flutter version 3.16.9