钛合金型号 - 表没有列 [英] Titanium Alloy Models - Table has no Column
问题描述
我是新来的钛及其合金,但我在3个月左右的使用后感觉舒适大部分。不过,我pretty新的合金模型和我快到我想不出一个错误。下面是我如何模型和控制器设置(不包括视图.XML文件,因为它是不相关)
I'm new to Titanium and Alloy but I feel comfortable with most of it at after about 3 months of use. I am however pretty new to Models in Alloy and I'm running into an error which I can't figure out. The following is how my model and controller is set up (excluding the view .XML file as it's irrelevant)
Orders.js |型号
exports.definition = {
config : {
columns : {
"id_Orders" : "INTEGER PRIMARY KEY AUTOINCREMENT",
"reseller_name" : "TEXT",
"reseller_invoice_account" : "TEXT"
},
adapter : {
type : "sql",
collection_name : "orders",
idAttribute: "id_Orders"
}
}
Orders.js |控制器
var network = require("network");
network.soapRequest("<prem:getResellersRequest/>", function(a) {
Ti.API.info("The Soap Server Returned: " + JSON.stringify(a));
Ti.API.info("There are " + a.reseller_name.length + " returned records.");
for (var i = 0; a.reseller_name.length > i; i++) {
var listModel = Alloy.createModel("orders", {
reseller_name: a.reseller_name[i],
reseller_invoice_account: a.reseller_invoice_account[i]
});
listModel.save();
Alloy.Collections.orders.fetch();
}
});
Alloy.Collections.orders.fetch();
在listModel.save()行出现的错误:
The error occurs at the listModel.save() line:
执行错误SQL:表中的订单有没有名为RESELLER_NAME列:,在编译:更换成订单(id_Orders,RESELLER_NAME,reseller_invoice_account)VALUES;
网络是发送SOAP请求到网络服务器并将其转换为JSON使用soap2json.js一个lib。我相信没有什么错与网络的一部分。
我是pretty肯定有提错返回的JSON对象'一'。我可以输出的所有单独的值和其他地方使用它 - 当我试图保存模型到集合时出现错误。
Network is a lib that sends a SOAP request to a webserver and converts it to JSON using soap2json.js. I'm convinced there's nothing wrong with the network part. I'm pretty sure there's noting wrong with the returned JSON object 'a'. I can output all of the values individually and use it elsewhere - the error occurs when I'm trying to save the model to the collection.
我缺少的东西吗?
推荐答案
这是当你修改模型的定义应用程序的第一次运行之后,也许你,之后加入RESELLER_NAME列通常发生。您必须重新生成表。
That usually happens when you modify the definition of the model after a first run of the application, probably you and added the reseller_name column after that. You must regenerate the table.
当它发生在我身上,我在开发阶段,我通常在alloy.js文件的开头做表的下降。试试这个:
When it happens to me and I'm in the development stage, I usually do a DROP of the table at the beginning of alloy.js file. Try this:
var db = Ti.Database.open ('_alloy_');
db.Execute ('DROP TABLE IF EXISTS orders;');
db.close ();
显然,这会破坏任何表中的数据,但合金重新生成新的定义表你instancies集合或模型中的第一次。
Obviously this destroys any data in the table, but Alloy regenerate the table with the new definition the first time you instancies a collection or a model.
如果你需要保持你的数据是使用的迁移
The proper way to handle these changes if you need to keep your data is to use migrations
这篇关于钛合金型号 - 表没有列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!