You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Realm同步报错:MatchFormSettingsSchema的questionsArray字段类型未知

解决方案

1. 补充嵌入式对象Schema到Realm配置

错误核心是Realm无法识别Question类型,尽管MatchFormSettingsSchema引用了这个嵌入式对象,但需要在Realm配置里显式声明它的Schema。修改初始化代码:

final realmConfig = Configuration.flexibleSync(
  user,
  [
    MatchSchema.schema,
    MatchFormSettingsSchema.schema,
    Question.schema, // 新增该行,添加嵌入式对象的Schema
  ],
);

2. 重新执行Realm代码生成

确保已运行代码生成命令,让框架正确生成Question对应的Realm类文件:

flutter pub run realm generate

3. 校验Atlas Sync的Schema配置

在MongoDB Atlas后台检查同步规则:

  • 确认MatchFormSettingsSchema的questionsArray字段类型为Array,数组内的对象为Embedded Document,且包含input、type两个字符串属性。
  • 确保Question作为嵌入式对象的Schema已同步到Atlas(自动同步场景下通常无需手动操作,但若手动配置过Schema需核对)。

额外排查点

  • 检查_Question类的注解@RealmModel(ObjectType.embeddedObject)是否拼写正确。
  • 查看项目中自动生成的.realm.g.dart文件,确认Question类已被正确生成。

内容的提问来源于stack exchange,提问作者AndromedaHelix

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 09:22:40