[ZBX-19435] Upgrade to 5.4 causes failure "Cannot change column 'scriptid'" Created: 2021 May 22  Updated: 2024 Apr 10  Resolved: 2023 Nov 10

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Installation (I), Server (S)
Affects Version/s: 5.0.10, 5.0.11, 5.4.0
Fix Version/s: 7.0 (plan)

Type: Problem report Priority: Trivial
Reporter: Tom Plessers Assignee: Martins Valkovskis
Resolution: Fixed Votes: 9
Labels: crash, database, patch
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu 18.04 LTS with MariaDB 10.1 and Apache


Attachments: PNG File image-2021-06-09-14-36-32-387.png     File schema-1.sql     File schema.sql    
Issue Links:
Sub-task
depends on ZBX-20224 Database upgrade script 05030153 to 0... Closed
Team: Team C
Sprint: Sprint 76 (May 2021), Sprint 77 (Jun 2021), Sprint 78 (Jul 2021), Sprint 79 (Aug 2021), Sprint 80 (Sep 2021), Sprint 81 (Oct 2021), Sprint 82 (Nov 2021), Sprint 83 (Dec 2021), Sprint 84 (Jan 2022), Sprint 85 (Feb 2022), Sprint 86 (Mar 2022), Sprint 87 (Apr 2022), Sprint 88 (May 2022), Sprint 89 (Jun 2022), Sprint 90 (Jul 2022), Sprint 91 (Aug 2022), Sprint 92 (Sep 2022), Sprint 93 (Oct 2022), Sprint 94 (Nov 2022), Sprint 95 (Dec 2022), Sprint 96 (Jan 2023), Sprint 97 (Feb 2023), Sprint 98 (Mar 2023), Sprint 99 (Apr 2023), Sprint 100 (May 2023), Sprint 101 (Jun 2023), Sprint 102 (Jul 2023), Sprint 103 (Aug 2023), Sprint 104 (Sep 2023), Sprint 105 (Oct 2023), Sprint 106 (Nov 2023)
Story Points: 0.5

 Description   

 

There are multiple people experiencing this bug, there are 2 threads in the forum with at least 4 people experiencing it, across multiple Debian-based operating systems (Ubuntu and Raspbian). See links below to forum threads. Possible solution has also been found, see below or in the forum threads

Steps to reproduce:

  1. Follow upgrade procedure to upgrade from Zabbix 5.0 LTS to 5.4
  2. Upgrade result = all OK, all components updated correctly
  3. Web interface shows
    "The Zabbix database version does not match current requirements. Your database version: 5030069. Required version: 5040000. Please contact your system administrator."
  1. Checking the zabbix_server.log gives the following
Unsupported DB! MariaDB version is 50505 which is smaller than minimum of 100037
current database version (mandatory/optional): 05030069/05030069
required mandatory version: 05040000
starting automatic database upgrade
[Z3005] query failed: [1832] Cannot change column 'scriptid': used in a foreign key constraint 'c_opcommand_2' [alter table opcommand modify `scriptid` bigint unsigned not null]
database upgrade failed

Additional information
Someone suggested to run "show columns from zabbix.opcommand;" which has the following result for someone experiencing this issue

MariaDB [(none)]> show columns from zabbix.opcommand;
+-------------+---------------------+------+-----+---------+-------+
| Field       | Type                | Null | Key | Default | Extra |
+-------------+---------------------+------+-----+---------+-------+
| operationid | bigint(20) unsigned | NO   | PRI | NULL    |       |
| scriptid    | bigint(20) unsigned | YES  | MUL | NULL    |       |
+-------------+---------------------+------+-----+---------+-------+

And should show the following for someone not experiencing this issue

MariaDB [(none)]> show columns from zabbix.opcommand;
+-------------+---------------------+------+-----+---------+-------+
| Field       | Type                | Null | Key | Default | Extra |
+-------------+---------------------+------+-----+---------+-------+
| operationid | bigint(20) unsigned | NO   | PRI | NULL    |       |
| scriptid    | bigint(20) unsigned | NO   | MUL | NULL    |       |
+-------------+---------------------+------+-----+---------+-------+

So the 'Null' column is different, for someone experiencing this issue it is 'null allowed' while for someone not experiencing this issue it is 'null not allowed'

Our database architect suggested that the database upgrade script doesn't drop foreign key 'c_opcommand_2' before editing the column and that they need to be dropped and re-added. This is confirmed so far by one user who manually dropped the foreign key using the following procedure, after which the problem was solved for him. I am going to try this on Tuesday and suspect it will solve my problem as well

ALTER TABLE zabbix.opcommand DROP FOREIGN KEY c_opcommand_2;
ALTER TABLE `opcommand` CHANGE `scriptid` `scriptid` BIGINT(20) UNSIGNED NOT NULL;
ALTER TABLE `opcommand` ADD CONSTRAINT `c_opcommand_2` FOREIGN KEY (`scriptid`) REFERENCES `scripts`(`scriptid`) ON DELETE RESTRICT ON UPDATE RESTRICT;

So this is almost certainly a bug with the database update script and because it happened to 4 different people at least across 2 different operating systems, more people will run into this without a doubt. If you need more information don't hesitate to contact me on my email

**

 

Links to forum threads discussing this
First thread
Second thread



 Comments   
Comment by Tom Plessers [ 2021 May 22 ]

Apologies, I have made a mistake: I have tried upgrading to Zabbix 5.4, which is of course not an LTS version as there is no Zabbix 5.4 LTS

Comment by Tom Plessers [ 2021 May 22 ]

Second forum user confirms the solution mentioned above works for him

Comment by Igor Gorbach (Inactive) [ 2021 May 24 ]
[Z3005] query failed: [1832] Cannot change column 'scriptid': used in a foreign key constraint 'c_opcommand_2' [alter table opcommand modify `scriptid` bigint unsigned not null]

Cannot reproduce

Unsupported DB! MariaDB version is 50505 which is smaller than minimum of 100037

Confirmed

Closing as a dublicae of ZBX-19400

Comment by CyberMCM [ 2021 May 24 ]

There are more reports of 

// Cannot change column 'scriptid': used in a foreign key constraint 'c_opcommand_2' [alter table opcommand modify `scriptid` bigint unsigned not null]

This issue wasn't created about the MariaDB version, so in my point of view not a duplicate.

Comment by Tom Plessers [ 2021 May 24 ]

I agree CyberMCM. The "cannot chance column....." error seems to be unique to this issue and does not appear with the other issue. I don't think this is a duplicate and I do think this is a bug. @Igor: there are so far 5 users that have experienced this specific error so it is something reproducible but the question is, how?

Comment by Tom Plessers [ 2021 May 24 ]

Another member has come forward and told us he has this exact issue and that the solution has worked for him. So that makes 6 people with this exact issue and 3 people for whom this solution worked. I will not push so if you don't want to take a look at this, that is fine, we have a solution but I request this issue to be reopened and the "is duplicate" to be removed

edit

Thank you Igor, much appreciated. If anyone on the support team needs more data I'll be happy to provide it, just give me a shout. Also, I have encountered someone in another forum that had this issue and he told me that the issue went away when he didn't upgrade from 5.0 to 5.4 directly but first upgraded 5.0 to 5.2 and then to 5.4. So maybe the bug can be found by comparing 5.4 to 5.2, specifically the database upgrade script?

Link: here see the comment from Алексей (Alexei in English translation) and Aperam Support (Aperam Support is me). It is a Russian forum though but some comments are in English

Comment by Dmitrijs Lamberts [ 2021 May 25 ]

Hello,
Please note that this issue closed as duplicate of ZBX-19400

Comment by Tom Plessers [ 2021 May 25 ]

ZBX-19400 does not have the error

// Cannot change column 'scriptid': used in a foreign key constraint 'c_opcommand_2' [alter table opcommand modify `scriptid` bigint unsigned not null]

So in my opinion it is not a duplicate. The solution in our case is also not to update MariaDB but to drop the foreign key 'c_opcommand_2' mentioned in the above error, to then change the 'Null' option to 'No' on column 'scriptid' and to then add the foreign key again. But, we have a solution so as far as I'm concerned I have done my part

Comment by Chris Kistner [ 2021 May 25 ]

I don't see how this issue is a duplicate of ZBX-19400 at all, unless the database version detection results in different commands being executed with the upgrade that could result in this specific foreign key being an issue.

We experienced this exact same issue when we upgraded from Zabbix 5.2.4 to 5.5.0 with an Aurora MySQL 5.6.10a cluster that was behind a ProxySQL server that still reported 5.5.30 as its version.

Our Zabbix server was incrementally upgraded from like 4.4 -> 5.0 -> 5.2 -> 5.4

After we first experienced this foreign key issue and that Zabbix said the "MySQL version is 50530 which is smaller than minimum of 50728", we upgraded our Aurora MySQL to 5.7, but unfortunately it caps at 5.7.12, and ofcourse this did not fix the stuck upgrade issue for us.

Our solution was also to drop the foreign key and then start the Zabbix 5.4.0 server again, however we still need to recreate the foreign key.

Comment by Marco Hofmann [ 2021 May 26 ]

How is this marked as a Duplicate? This is clearly a different error.

Comment by dimir [ 2021 May 27 ]

Right. Re-opening. This issue mentions incorrect DB version detection in the log file but this is not the cause of the upgrade patch

alter table opcommand modify `scriptid` bigint unsigned not null 

failure.

Comment by Dmitrijs Lamberts [ 2021 Jun 03 ]

Could you attach your database schema ( without any data ) before the upgrade?

Comment by CyberMCM [ 2021 Jun 03 ]

sorry, I can't provide db schema, was my home installation and backup from before upgrade was already overwritten

Comment by Tom Plessers [ 2021 Jun 03 ]

I have a checkpoint from before the upgrade, I'll see what I can do once I'm at work, should be possible to provide the schema. I'll provide feedback in a bit

Comment by Tom Plessers [ 2021 Jun 03 ]

Is the below what you need? This is a schema exported with mysqldump --no-data after restoring the checkpoint from before the upgrade. I am not well-versed with database management so it could be that I have exported it incorrectly, just tell me what the correct way is then and I'll try again

schema.sql

Comment by Igor [ 2021 Jun 05 ]

Just throwing my hat in the ring to report that I also am experiencing the same exact problem. I am trying to upgrade from 5.2 to 5.4 and getting the 'scriptid' error in the server logs.

My instance is running on Ubuntu 18.04 LTS with MySQL as the back end.

I'd love to provide the database schema as another data point but I have no idea how to pull that out.

If I got some instructions on what I can provide for further troubleshooting I'd be happy to.

Comment by MArk [ 2021 Jun 06 ]

Igor, I think Tom did something like this:

mysqldump -d zabbix > schema.sql
Comment by Igor [ 2021 Jun 06 ]

Got it, thanks Mark.

Attached.

schema.sql

Comment by Vadim Volodin [ 2021 Jun 09 ]

Install Zabbix server at Ubuntu Server 20.04.2

1143:20210609:111428.161 Zabbix Server stopped. Zabbix 5.4.1 (revision ecb5b3378c).
3383:20210609:112238.776 Starting Zabbix Server. Zabbix 5.4.1 (revision ecb5b3378c).
3383:20210609:112238.776 using configuration file: /etc/zabbix/zabbix_server.conf
3383:20210609:112238.790 Unsupported DB! MariaDB version is 50505 which is smaller than minimum of 100037
3383:20210609:112238.792 current database version (mandatory/optional): 05040000/05040000
3383:20210609:112238.792 required mandatory version: 05040000

 

Comment by Tom Plessers [ 2021 Jun 09 ]

Vadim, do you also have the below error in zabbix_server.log? If not, this is probably a separate issue, I have linked that separate issue below

[Z3005] query failed: [1832] Cannot change column 'scriptid': used in a foreign key constraint 'c_opcommand_2' [alter table opcommand modify `scriptid` bigint unsigned not null]

Link to separate issue

Comment by Dmitry Kolosov [ 2021 Jun 13 ]

Hi! Same issue on my Zabbix host. Zabbix 5.4.1, Ubuntu 20.04, MariaDB 10.5.10

On Zabbix dashboard: MariaDB 5.05.05 Minimum required database version is 10.00.37.

Zabbix_server.log: Unsupported DB! MariaDB version is 50505 which is smaller than minimum of 100037.

No errors in mysql error log.

I guess it would be fixed in next 5.4.2 release? Thank you!

 

Comment by CyberMCM [ 2021 Jun 13 ]

@Dimitry Kolosov: This issue isn't about the version mismatch, this is covered here

Comment by Philip Iezzi [ 2021 Jun 25 ]

Hi there! Is there a fix for this in the works?
We could drop FK constraint 'c_opcommand_2' and re-add it after migration, but that seems like an ugly workaround to me.

Experiencing the same on Zabbix 5.2.6 -> 5.4.1 upgrade:

  • Debian Buster 10.10
  • Percona Server for MySQL 8.0: 8.0.23-14 Percona Server (GPL), Release '14', Revision '3558242'

/var/log/zabbix/zabbix_proxy.log:

Starting Zabbix Proxy (passive) [Zabbix-Proxy]. Zabbix 5.4.1 (revision ecb5b3378c).
**** Enabled features ****
SNMP monitoring:       YES
IPMI monitoring:       YES
Web monitoring:        YES
VMware monitoring:     YES
ODBC:                  YES
SSH support:           YES
IPv6 support:          YES
TLS support:           YES
**************************
using configuration file: /etc/zabbix/zabbix_proxy.conf
current database version (mandatory/optional): 05030069/05030069
required mandatory version: 05040000
starting automatic database upgrade
[Z3005] query failed: [1832] Cannot change column 'scriptid': used in a foreign key constraint 'c_opcommand_2' [alter table opcommand modify `scriptid` bigint unsigned not null]
database upgrade failed

zabbix.opcommand schema dump:

$ mysqldump -d zabbix opcommand
CREATE TABLE `opcommand` (
  `operationid` bigint unsigned NOT NULL,
  `type` int NOT NULL DEFAULT '0',
  `scriptid` bigint unsigned DEFAULT NULL,
  `execute_on` int NOT NULL DEFAULT '0',
  `port` varchar(64) COLLATE utf8_bin NOT NULL,
  `authtype` int NOT NULL DEFAULT '0',
  `username` varchar(64) COLLATE utf8_bin NOT NULL,
  `password` varchar(64) COLLATE utf8_bin NOT NULL,
  `publickey` varchar(64) COLLATE utf8_bin NOT NULL,
  `privatekey` varchar(64) COLLATE utf8_bin NOT NULL,
  `command` text COLLATE utf8_bin NOT NULL,
  PRIMARY KEY (`operationid`),
  KEY `opcommand_1` (`scriptid`),
  CONSTRAINT `c_opcommand_1` FOREIGN KEY (`operationid`) REFERENCES `operations` (`operationid`) ON DELETE CASCADE ON UPDATE RESTRICT,
  CONSTRAINT `c_opcommand_2` FOREIGN KEY (`scriptid`) REFERENCES `scripts` (`scriptid`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
$ mysql zabbix -e 'show columns from zabbix.opcommand'
+-------------+-----------------+------+-----+---------+-------+
| Field       | Type            | Null | Key | Default | Extra |
+-------------+-----------------+------+-----+---------+-------+
| operationid | bigint unsigned | NO   | PRI | NULL    |       |
| type        | int             | NO   |     | 0       |       |
| scriptid    | bigint unsigned | YES  | MUL | NULL    |       |
| execute_on  | int             | NO   |     | 0       |       |
| port        | varchar(64)     | NO   |     | NULL    |       |
| authtype    | int             | NO   |     | 0       |       |
| username    | varchar(64)     | NO   |     | NULL    |       |
| password    | varchar(64)     | NO   |     | NULL    |       |
| publickey   | varchar(64)     | NO   |     | NULL    |       |
| privatekey  | varchar(64)     | NO   |     | NULL    |       |
| command     | text            | NO   |     | NULL    |       |
+-------------+-----------------+------+-----+---------+-------+

any help greatly appreciated! Thanks!

Comment by Philip Iezzi [ 2021 Jun 25 ]

this workaround worked fine for me:

1. Drop FK constraint

ALTER TABLE `zabbix`.`opcommand` DROP FOREIGN KEY `c_opcommand_2`;

2. Start zabbix-proxy (or zabbix-server)

$ systemctl start zabbix-proxy

DB migrations then went through fine. Wait a while until you complete step 3, check /var/log/zabbix/zabbix_proxy.log (or /var/log/zabbix/zabbix_server.log) and look for the following lines:

completed 100% of database upgrade
database upgrade fully completed

3. Re-add FK constraint

ALTER TABLE `zabbix`.`opcommand` ADD CONSTRAINT `c_opcommand_2` FOREIGN KEY (`scriptid`) REFERENCES `scripts` (`scriptid`) ON DELETE RESTRICT ON UPDATE RESTRICT;
Comment by Igor [ 2021 Jun 25 ]

Philip,

Did you perform these steps after upgrading to 5.4.2 or before running the upgrade?

Comment by Philip Iezzi [ 2021 Jun 25 ]

Hi @Dobrosavljevic,

Did you perform these steps after upgrading to 5.4.2 or before running the upgrade?

On a zabbix-proxy instance, I performed this step (dropping FK constraint 'c_opcommand_2') AFTER upgrading to Zabbix 5.4.1, but BEFORE starting zabbix-proxy (as the Systemd service did not start after failed upgrade because of this issue).

On a zabbix-server instance, I performed this step (dropping FK constraint 'c_opcommand_2') BEFORE upgrading to Zabbix 5.4.1. The whole upgrade went through fine and I was able to re-add the FK constraint afterwards.

Basically the same effect, as Zabbix db migrations are not part of package upgrade, but only happen on first start of Zabbix-server/-proxy, so that issue did not break the upgrade itself.
 
And AFAIK, Zabbix 5.4.2 is not out yet, currently still on 5.4.2rc2. So, I have upgraded from official deb package repo from 5.2.6 to 5.4.1

Comment by Igor [ 2021 Jun 25 ]

Thank you.

Comment by Diez [ 2021 Oct 07 ]

Can confirm this on alpine docker images as well. Upgrade from alpine-5.0-latest to alpine-5.4-latest.

Sql script from db architect solved the issue.

Comment by Marco Hofmann [ 2021 Nov 08 ]

We are planing to upgrade from 5.2.7 to 5.4.7 this Friday. I'm quite positive this will be a success, but this issue here, gives me a bad feeling.

Why isn't this being worked on, with Zabbix 5.4 being available for 6 months now?

Any news about how I can handle this?

Comment by Philip Iezzi [ 2021 Nov 08 ]

Marco, see my comment above, this is the only thing you need to do BEFORE upgrading:

ALTER TABLE `zabbix`.`opcommand` DROP FOREIGN KEY `c_opcommand_2`;

and right AFTER upgrading, re-add this FK constraint:

ALTER TABLE `zabbix`.`opcommand` ADD CONSTRAINT `c_opcommand_2` FOREIGN KEY (`scriptid`) REFERENCES `scripts` (`scriptid`) ON DELETE RESTRICT ON UPDATE RESTRICT;

But... I would strongly advice NOT to upgrade to Zabbix 5.4! Aside this issue, I struggled with a lot of other regressions after upgrading from Zabbix 5.2 to 5.4 (e.g. ZBX-19481 was reintroduced and only fixed in 5.4.3). Seems like they didn't quite put enough of love into this release. According to the roadmap Zabbix 6.0 LTS is planned for Q4 2021. Rather wait for that release and maybe some first minor version. An LTS version must be taken more serious by the Zabbix devs and issues must be fixed faster, I hope.

I told myself to stick only with LTS releases in the future.

Comment by Marco Hofmann [ 2021 Nov 08 ]

onlime Thanks for your reply. I will make a test run before Friday, and clone the VM.

Regarding your warning, yes 5.4 seems of less quality than previous releases, that's the reason we waited until 5.4.7 with the upgrade, as I have the strong feeling, that the most important bugs are fixed by now.

Regarding the upcoming LTS, we are at 6.0 alpha5 now, and the stable will be GA around Zabbix summit'21 I guess, so maybe we won't stick with 5.4 for so long.
But as Zabbix 5.2 is unsupported for quite some time now, and 5.4 has fixed quite a few bugs that were present in 5.2 but never fixed, I feel quite the need to switch.

Comment by Thibaut KORNMANN [ 2022 May 02 ]

Hi,

Got exactly this error from 5.0.20 to 6.0.3. Do we have any updates ?

We are waiting to update our clients from 5 LTS to 6 LTS.

Comment by Konstantins Prutkovs (Inactive) [ 2022 May 31 ]

According to this bug report for MySQL it is not allowed to alter the table when the sql_mode is not strict. This is confirmed in the MySQL documentation here. In case of MariaDB I was unable to reproduce the issue.

DieWeb21 and BlueBull can You please provide me the output of the following SQL command:

SELECT @@sql_mode; 

 

The configuration files /etc/mysql/my.cnf or /etc/mysql/mariadb.cnf can contain the setting for sql_mode under section [mysqld].  As a workaround you can also execute the following sql command as a root user before updating Zabbix database:

SET GLOBAL sql_mode="STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION";
Comment by Thibaut KORNMANN [ 2022 Jun 27 ]

Hi,

My sql_mode is empty.
sql_mode = "" in my /etc/my.cnf file.

Comment by Tom Plessers [ 2022 Jun 27 ]

Woops, forgot to reply. Output of command is as follows:

+--------------------------------------------+
| @@sql_mode                                 |
+--------------------------------------------+
| NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+--------------------------------------------+

The workaround I will try soon in my test environment

Comment by Konstantins Prutkovs (Inactive) [ 2022 Jun 28 ]

DieWeb21 , BlueBull well, it seems that what you have set to sql_mode is causing the issue. The sql_mode should be outputting by default:

"STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

You can try to do one of the following, set sql_mode for all the sessions and upgrade like I did in the comment above, or (should be more reliable) configure your mysql to have the sql_mode set to the value mentioned above.

Comment by Tom Plessers [ 2022 Jun 28 ]

I have not set anything, the database is running using the settings provided by the zabbix documentation, without exception. If that setting is wrong, it means that it has changed automatically, not manually. My point with saying this is that I suspect there are particular circumstances where that settings changes to the wrong one. It might for instance be in specific versions of MariaDB that this setting is different or something, or because of another reason. I will try out the fix as soon as possible but this might take some time

[kprutkovs] It is not relevant whether it changed automatically or not. A command altering the column in question cannot succeed if the STRICT_TRANS_TABLES is not specified in the sql_mode as it is a limitation of MySql. The sql_mode needs to be adjusted in order to upgrade if the setting is not specified already.

Comment by Konstantins Prutkovs (Inactive) [ 2022 Aug 26 ]

WON'T FIX as it is setup issue and needs documenting

Comment by Arturs Dancis [ 2023 Nov 08 ]

Documentation updated:

Generated at Sun Apr 06 12:11:29 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.