{"timestamp":"2021-11-09 10:57:43.933 +01:00","level":"fatal","msg":"Failed to alter column type. It is likely you have invalid JSON values in the column. Please fix the values manually and run the migration again.","caller":"sqlstore/store.go:860","error":"pq: default for column \"notifyprops\" cannot be cast automatically to type jsonb","tableName":"ChannelMembers","columnName":"NotifyProps"}
I have seen several similar posts concerning database schema alteration problems, but I haven´t found a solution that works for me. Any ideas?
Customers upgrading from releases older than v5.35 following our recommended upgrade process may encounter the following error during the upgrade to v6.0:
Failed to alter column type. It is likely you have invalid JSON values in the column. Please fix the values manually and run the migration again.",“caller”:“sqlstore/store.go:854”,“error”:"pq: unsupported Unicode escape sequence
To assist with troubleshooting, you can enable SqlSettings.Trace to narrow down what table and column are causing issues during the upgrade. The following queries change the columns to JSONB format in PostgreSQL. Run these against your v5.39 development database to find out which table and column has Unicode issues:
ALTER TABLE posts ALTER COLUMN props TYPE jsonb USING props::jsonb;
ALTER TABLE channelmembers ALTER COLUMN notifyprops TYPE jsonb USING notifyprops::jsonb;
ALTER TABLE jobs ALTER COLUMN data TYPE jsonb USING data::jsonb;
ALTER TABLE linkmetadata ALTER COLUMN data TYPE jsonb USING data::jsonb;
ALTER TABLE sessions ALTER COLUMN props TYPE jsonb USING props::jsonb;
ALTER TABLE threads ALTER COLUMN participants TYPE jsonb USING participants::jsonb;
ALTER TABLE users ALTER COLUMN props TYPE jsonb USING props::jsonb;
ALTER TABLE users ALTER COLUMN notifyprops TYPE jsonb USING notifyprops::jsonb;
ALTER TABLE users ALTER COLUMN timezone TYPE jsonb USING timezone::jsonb;
Once you’ve identified the table being affected, verify how many invalid occurrences of u0000 you have using the following SELECT query:
SELECT COUNT(*) FROM TableName WHERE ColumnName LIKE '%\u0000%';
Then select and fix the rows accordingly. If you prefer, you can also fix all occurrences at once in a given table or column using the following UPDATE query:
UPDATE TableName SET ColumnName = regexp_replace(ColumnName, '\\u0000', '', 'g') WHERE ColumnName LIKE '%\u0000%';
More than two months later, I tried to upgrade from 5.39 to the fresh version 6.30. Hoped, that something has changed in the meantime, but it still fails:
{
"timestamp":"2022-01-20 14:47:37.689 +01:00",
"level":"fatal",
"msg":"Failed to alter column type. It is likely you have invalid JSON values in the column. Please fix the values manually and run the migration again.",
"caller":"sqlstore/store.go:932",
"error":"pq: default for column \"notifyprops\" cannot be cast automatically to type jsonb",
"tableName":"ChannelMembers",
"columnName":"NotifyProps"
}
I would really appreciate any help here, I have no idea how this can be solved.
Hi @agnivade , that helped, runs like a charm. Thank you so much! My Mattermost instance is quite old, started with the first Beta versions and received countless updated from then. Maybe that´s the reason for this issue.