gpt4 book ai didi

sqlite - Titanium JS:尝试应用数据库迁移时出错

转载 作者:行者123 更新时间:2023-12-03 19:44:10 25 4
gpt4 key购买 nike

我在models/beers.js文件中添加了新列,该列需要为我的应用程序的当前用户迁移数据库。我根据documentation创建了迁移,但是现在当我在模拟器中运行应用程序时,出现以下错误:

[ERROR] :  Script Error {
[ERROR] : backtrace = "#0 Migrate() at file:///Users/owen/Library/Application%20Support/iPhone%20Simulator/7.1-64/Applications/2BAE6ECA-8995-4E0F-BA2F-9CF00162E81E/Beer%20Pad.app/alloy/sync/sql.js:245\n#1 () at file:///Users/owen/Library/Application%20Support/iPhone%20Simulator/7.1-64/Applications/2BAE6ECA-8995-4E0F-BA2F-9CF00162E81E/Beer%20Pad.app/alloy/sync/sql.js:329\n#2 () at file:///Users/owen/Library/Application%20Support/iPhone%20Simulator/7.1-64/Applications/2BAE6ECA-8995-4E0F-BA2F-9CF00162E81E/Beer%20Pad.app/alloy.js:95\n#3 () at file:///Users/owen/Library/Application%20Support/iPhone%20Simulator/7.1-64/Applications/2BAE6ECA-8995-4E0F-BA2F-9CF00162E81E/Beer%20Pad.app/alloy/models/Beers.js:100";
[ERROR] : line = 72;
[ERROR] : message = "invalid SQL statement";
[ERROR] : nativeLocation = "-[TiDatabaseProxy execute:] (TiDatabaseProxy.m:191)";
[ERROR] : nativeReason = "Error Domain=com.plausiblelabs.pldatabase Code=3 \"An error occured parsing the provided SQL statement.\" UserInfo=0xfa7d920 {com.plausiblelabs.pldatabase.error.vendor.code=1, NSLocalizedDescription=An error occured parsing the provided SQL statement., com.plausiblelabs.pldatabase.error.query.string=ALTER TABLE beers ADD COLUMN is_sample BOOLEAN;, com.plausiblelabs.pldatabase.error.vendor.string=no such table: beers}";
[ERROR] : sourceId = 351886816;
[ERROR] : sourceURL = "file:///Users/owen/Library/Application%20Support/iPhone%20Simulator/7.1-64/Applications/2BAE6ECA-8995-4E0F-BA2F-9CF00162E81E/Beer%20Pad.app/alloy/models/Beers.js";
[ERROR] : }
[ERROR] : Script Error Module "alloy/models/Beers" failed to leave a valid exports object


这是我的模型文件代码

exports.definition = {
config: {
columns: {
"name": "text",
"brewery": "text",
"rating": "integer",
"percent": "integer",
"establishment": "text",
"location": "text",
"notes": "text",
"date": "text",
"date_string": "text",
"beer_image": "text",
"latitude": "integer",
"longitude": "integer",
"favourite": "boolean",
"is_sample": "boolean" // this is the new column
},
adapter: {
type: "sql",
collection_name: "beers"
}
}
/* and so on ... */


这是我最近添加的迁移文件:

201405291604237_Beers.js

migration.up = function(migrator) {
migrator.db.execute('ALTER TABLE ' + migrator.table + ' ADD COLUMN is_sample BOOLEAN;');
};

migration.down = function(migrator) {
var db = migrator.db;
var table = migrator.table;
db.execute('CREATE TEMPORARY TABLE beers_backup(alloy_id,name,brewery,rating,percent,establishment,location,notes,date,date_string,beer_image,latitude,longitude,favourite);');
db.execute('INSERT INTO beers_backup SELECT alloy_id,name,brewery,rating,percent,establishment,location,notes,date,date_string,beer_image,latitude,longitude,favourite FROM ' + table + ';');
migrator.dropTable();
migrator.createTable({
columns: {
"name": "text",
"brewery": "text",
"rating": "integer",
"percent": "integer",
"establishment": "text",
"location": "text",
"notes": "text",
"date": "text",
"date_string": "text",
"beer_image": "text",
"latitude": "integer",
"longitude": "integer",
"favourite": "boolean"
},
});
db.execute('INSERT INTO ' + table + ' SELECT alloy_id,name,brewery,rating,percent,establishment,location,notes,date,date_string,beer_image,latitude,longitude,favourite FROM beers_backup;');
db.execute('DROP TABLE beers_backup;');
};


那么,我在哪里错了?我遵循了文档中的示例以及一些教程。

最佳答案

阅读错误消息。


NSLocalizedDescription =在解析提供的SQL时发生错误
语句。,com.plausiblelabs.pldatabase.error.query.string = ALTER
TABLE BERS ADD COLUMN is_sample BOOLEAN ;,
com.plausiblelabs.pldatabase.error.vendor.string =没有这样的表:
啤酒}”;


您正在尝试ALTER TABLE啤酒,但没有这样的表格。

关于sqlite - Titanium JS:尝试应用数据库迁移时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24477887/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com