我从YDN-DB开始遇到问题。我的意思是。我设置了一个方案,我初始化了数据库,但是在实例化时抛出一个错误,上面写着“ConstraintError:DOM Exception IDBDatabase 0”。在事件处理程序“失败”给我“版本更改事务在upgradeneeded事件处理程序中被中止。”。阅读我在this link找到的问题。无法找到分配事件以触发“onupgradeneeded”的方式,我认为这样可以解决问题
我留下了我的代码:
var shopgroups_schema = {
name: 'shopgroups',
keyPath: 'id_shop_group',
autoIncrement: true,
indexes: [
{keyPath: 'id_shop_group'},
{keyPath: 'name'},
{keyPath: 'share_customer'},
{keyPath: 'share_order'},
{keyPath: 'share_stock'},
{keyPath: 'active'},
{keyPath: 'deleted'},
{keyPath: 'date_add'},
{keyPath: 'date_upd'},
{keyPath: 'date_upd'}
]
};
var shops_schema = {
name: 'shops',
keyPath: 'id_shop',
autoIncrement: true,
indexes: [
{keyPath: 'id_shop'},
{keyPath: 'id_shop_group'},
{keyPath: 'name'},
{keyPath: 'id_category'},
{keyPath: 'id_theme'},
{keyPath: 'active'},
{keyPath: 'deleted'},
{keyPath: 'date_add'},
{keyPath: 'date_upd'}
]
};
var schema = {
stores: [shopgroups_schema, shops_schema]
};
var schemaName = 'chollingApp4';
var db = new ydn.db.Storage(schemaName, schema);
db.addEventListener('error', function (event) {
var e = event.getError();
// common errors are AbortError, ConstraintError and UnknownError (possibliy for Quota exceed error).
// log error for debugging
console.log('connection failed with ' + e.name);
});
db.addEventListener('fail', function (event) {
var err = event.getError();
console.log(event);
console.log(err);
console.log('connection failed with ' + err.name + ' by ' + err.message);
db = null; // no operation can be placed to the database instance
});
db.addEventListener('ready', function (event) {
var is_updated = event.getVersion() != event.getOldVersion();
if (is_updated) {
console.log('database connected with new schema');
} else if (isNaN(event.getOldVersion())) {
console.log('new database created');
} else {
console.log('existing database connected');
}
// heavy database operations should start from this.
});
答案 0 :(得分:2)
ConstraintError
表明架构可能是个问题。我发现你有索引keyPath,date_upd
重复。