automigrate.js正常工作并在我的postgres数据库中创建食物表,但“真实”类型在我的数据库中映射为“整数”类型。 我想要映射到“数组”类型的“过敏原”被映射到整数。 错误在哪里?我需要改变什么? 我按照this tutorial
进行操作这是我的model.js
{
"name": "Food",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"name": {
"type": "string",
"required": true,
"postgres": {
"columnName": "name",
"dataType": "CHARACTER VARYING",
"dataLength": 50,
"dataPrecision": null,
"dataScale": null,
"nullable": "NO"
}
},
"carbs": {
"type": "number",
"dataType": "real",
"precision": 10,
"scale": 2,
"required": true,
"postgresql": {
"columnName": "carbs",
"dataType": "real",
"dataLength": null,
"dataPrecision": 10,
"dataScale": 2,
"nullable": "NO"
}
},
"fats": {
"type": "number",
"dataType": "REAL",
"precision": 10,
"scale": 2,
"required": true,
"postgres": {
"columnName": "fats",
"dataType": "REAL",
"dataLength": 50,
"dataPrecision": 10,
"dataScale": 2,
"nullable": "NO"
}
},
"proteins": {
"type": "number",
"dataType": "REAL",
"precision": 10,
"scale": 2,
"required": true,
"postgres": {
"columnName": "proteins",
"dataType": "REAL",
"dataLength": 50,
"dataPrecision": 10,
"dataScale": 2,
"nullable": "NO"
}
},
"allergens": {
"type": ["object"]
},
"style": {
"type": "object",
"postgres": {
"columnName": "style",
"dataType": "CHARACTER VARYING",
"dataLength": 50,
"dataPrecision": null,
"dataScale": null,
"nullable": "NO"
}
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
这是我的automigrate.js
'use strict';
var app = require('../server');
var dataSource = app.dataSources.softNutritionDB;
dataSource.automigrate('Food', function(err) {
if (err) throw err;
dataSource.disconnect();
});
答案 0 :(得分:0)
更改
"allergens": {
"type": ["object"]
},
要,
"allergens": {
"type": "object"
"postgres": {
"dataType": "json"
}
},
我将创建一个json列。
这应该有效,但理想情况下,根据规范化规则,您应该创建另一个表来存储过敏原映射。