I have the following table on 10.3.35 MariaDB server:
CREATE TABLE `_boat_product` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`standard` BIT(1) NOT NULL DEFAULT b'0',
`selected_by_default` BIT(1) NOT NULL DEFAULT b'0',
`date_created` DATETIME NULL DEFAULT current_timestamp(),
PRIMARY KEY (`id`) USING BTREE,
CONSTRAINT `CC1` CHECK (cast(`standard` as signed) + cast(`selected_by_default` as signed) <= 1)
)
COLLATE='utf8mb4_unicode_ci'
ENGINE=InnoDB
AUTO_INCREMENT=1486
;
I fetch data like this (PHP):
function select($order) {
$query = $this->db->query("SELECT id, "
. "standard,"
. "selected_by_default,"
. "DATE_FORMAT(date_created, '%Y-%m-%d %H:%i') date_created "
. "FROM _boat_product "
. $order);
return ['result' => 'OK', 'data' => $query->result()];
}
echo json_encode($this->select($order));
I have a tabulator.js table set like this (excerpt):
columns: [
{title: "standard", field: "standard", editor: "tickCross", minWidth: 50, maxWidth: 80, headerFilter: true, hozAlign: "center", headerVertical: true,
editorParams: {
trueValue: "1",
falseValue: "0"
}, formatter: "tickCross",
formatterParams: {
tickElement: "yes",
crossElement: "no"
}
},
{title: "default", field: "selected_by_default", editor: "tickCross", minWidth: 50, maxWidth: 80, headerFilter: true, hozAlign: "center", headerVertical: true,
editorParams: {
trueValue: "1",
falseValue: "0"
}, formatter: "tickCross",
formatterParams: {
tickElement: "yes",
crossElement: "no"
}
},...
Data that I am sending to the server to update records looks like this:
{
"data": {
"data": [
{
"id": "483",
"selected_by_default": "1",
"standard": "0"
}
],
"function": "insertUpdate"
}
}
and the update statement is like this:
UPDATE `_boat_product` SET `standard` = '0', `selected_by_default` = '1'
WHERE `id` = '483'
But I am getting an error that check constraint is violated:
Error Number: 4025</p><p>CONSTRAINT `CC1` failed for...
Why that is happening?