0
automigrate.js能夠正常工作並在我的postgres數據庫中創建食物表,但「真實」類型映射到我的數據庫中的「整數」類型。 我想要將映射到「數組」類型的「過敏原」映射爲整數。 錯誤在哪裏?我需要改變什麼? 我按照這個this tutorial如何使用loopback.js將具有特殊類型的模型遷移到postgresql
這是我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();
});
謝謝,昨天我爲過敏原創建了一個不同的表,它工作。你是否也有解決方案的真正價值? – michoprogrammer
真實價值是什麼意思? –
我的意思是實數(例如3.45,10.23,733.124,...)。看起來用實數遷移模型的唯一方法是遷移一個數字,然後在postgres中修改表。 – michoprogrammer