我是离子1.我已经在浏览器中测试了我的应用程序,它工作正常。我用过sqlite。我有一个表格。当我将一个文本输入字段留空时,数据被添加到数据库表中。这正是我想要的。但是,它不适用于设备。每当我离开一个字段为空它显示了以下错误:sqlite3_step失败:NOT NULL约束失败
Object {message: "sqlite3_step failure: NOT NULL constraint failed: items.barcode", code: 6}
这里是我的代码片段:
if ($scope.item.itemname && $scope.item.soldby && $scope.item.price) {
var query = "INSERT into items (itemname,category,soldby,price,sku,barcode) VALUES(?,?,?,?,?,?)";
$cordovaSQLite.execute(db, query, [$scope.item.itemname, $scope.item.category, $scope.item.soldby, $scope.item.price, $scope.item.sku, $scope.item.barcode,])
.then(function (result) {
console.log($scope.item.itemname);
console.log($scope.item.category);
console.log($scope.item.soldby);
console.log($scope.item.price);
console.log($scope.item.sku);
console.log("Printing barcode");
console.log($scope.item.barcode);
console.log($scope.item.total);
//ITEM ADDED SUCCESS POPUP STARTS
//ITEM ADDED SUCCESS POPUP ENDS
}, function (error) {
console.log(error);
});
// $scope.item = {
// itemname: $scope.item.itemname,
// };
$state.go('menu.allItems');
}
这里是我创建表的代码:
您是否曾在“条形码”列上使用NOT NULL约束表的以前版本? –
是的,我确实有。 –
那怎么办? @CL。 –