MySQL升级导致的Ghost博客系统升级错误

数据库默认设置导致的博客系统升级错误

MySQL升级导致的Ghost博客系统升级错误

例行升级Ghost的时候发现新版的Ghost需要MySQL 8,而我当前的版本为Ubuntu 18.04自带的MySQL 5。考虑这台虚拟机上并没有其它特殊的应用,于是直接将操作系统升级到Ubuntu 20.04,MySQL也随之升级到了8.0版本。一开始一切正常,然而再次升级Ghost的时候却遇到错误:

alter table `posts_products` add constraint `posts_products_post_id_foreign` foreign key (`post_id`) references `posts` (`id`) on delete CASCADE - UNKNOWN_CODE_PLEASE_REPORT: Referencing column 'post_id' and referenced column 'id' in foreign key constraint 'posts_products_post_id_foreign' are incompatible.

Google了一番终于找到了错误原因:

The default collation for charset utf8mb4 in MySQL 5.7 is utf8mb4_general_ci, but has been changed to utf8mb4_0900_ai_ci with MySQL 8.0.

解决方案参考作者解答:

Migration failed in latest version · Issue #288 · docker-library/ghost
I have been running ghost latest version in docker on Ubuntu 20.04 for quite a while...and it's been running fine... Now yesterday, after watchtower update, it failed with error alter table `po...

不过这种将默认设置回滚的做法不知道将来会不会有新的问题。最好的办法也许是将内容导出,重新安装Ghost然后再导入。以后有空在做吧。