我有一个这样定义的列:
@Column(nullable: true)
Document openHours; // List "openHours": ["Tuesday - Sunday: 11.00 - 21.00"],
在我的迁移文件中,我使用种子():
@override
Future seed() async {
const sClientSQL = ...
让我失望的 json 部分是:
"openHours": [
"Monday - Friday: 17.00 - 22.00",
"Saturday: 14:00 - 23:00",
"Sunday & Holidays: 11:30 - 22:00"
],
终端中的错误如下所示:
Seeding data from migration version 1...
*** There was an issue. Reason: Could not infer type of value '[Monday - Friday: 17.00 - 22.00,
Saturday: 14:00 - 23:00, Sunday & Holidays: 11:30 - 22:00]'.. Table: null Column: null
文档说:
Document map or list (Map<String, dynamic> or List<dynamic>)
JSON 对我来说看起来不错,但显然在这种情况下它是错误的。那么我在这里做错了什么?我找不到有关如何在渡槽中为 Document 类型编写 json 部分的示例。
谢谢大家并问候安东尼奥
[编辑 4]
下面是一个简短的查询示例:
const sClientSQL = 'INSERT INTO _Clients (name, owner, address, contacts, openhours, dayOff, description) VALUES (@name, @owner, @address, @contacts, @openhours, @dayOff, @description)';
await database.store.execute(sClientSQL, substitutionValues: {
'name': 'Dolce Vita',
'owner': 'David Driss',
'address': {
'street': 'Johannisstr. 3',
'zipCode': '54290',
'city': 'Trier'
},
'contacts': {
'phone': '0651 94 90 40',
'fax': '0651 43 23 2',
'mail': 'info@dolcevita.de'
},
'openhours': [
"Montag - Freitag: 17.00 - 22.00",
"Samstag: 14:00 - 23:00",
"Sonntag & Feiertag: 11:30 - 22:00"
],
'dayOff': '',
'description': 'Alle Speisen und Getränke sind inkl. MwST. Extrazutaten werden gesondert berechnet'
});
[编辑 1]
更多信息:
替换值与 Map 一样。
我使用了双引号,并将其更改为单引号,但没有效果。
[编辑 2]
在 dartpad 中尝试了复杂的地图并创建了一个要点来显示:
Dart Maps 示例的要点将代码放入 dartpad。
结果原样的地图是有效的。
[编辑 3]
- 我删除了所有 json 列以确保其正常工作。成功。
- 添加了一个 json 列,这是我之前展示的第一个示例。同样的问题
- 试图手动插入 jsonb 列。成功。
所以,只有await database.store.execute
命令不想要我的 json 类型文字。