Flutter Realm 修改数据模型后报错解决方法
Flutter Realm 修改数据模型后报错怎么办?
PropertyCarmake' has been removed.
Property 'Car.kilometers' has been removed.
Property 'Car.brand' has been added.
Property "Person.age' has been made optional.
Property "Person.sex' has been added.
如下:
以前的数据模型
import 'package:realm/realm.dart';
part 'main.g.dart';
@RealmModel()
class _Person {
late String name;
int age = 1;
}
后面改成了
import 'package:realm/realm.dart';
part 'main.g.dart';
@RealmModel()
class _Person {
late String name;
late String sex;
int age = 1;
}
这个时候运行可能提示 Property "Person.sex’ has been added.
如下图:
解决办法:配置schemaVersion
void initState() {
final config = Configuration.local([Car.schema,Person.schema],schemaVersion: 2);
realm = Realm(config);
super.initState();
}