> ## Content Index
> Fetch the complete content index at: https://yinguobing.com/blog/llms.txt
> Use this file to discover other available public pages before exploring further.

# MySQL升级导致的Ghost博客系统升级错误
- URL: https://yinguobing.com/blog/ghost-update-failed-due-to-mysql5-migration-mysql8/
- Published: 2022-10-31T03:19:29.000Z
- Updated: 2024-04-02T08:31:31.000Z
- Description: 数据库默认设置导致的博客系统升级错误
- Author: 尹国冰
- Tags: 新手入门

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

```bash
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/ghostI have been running ghost latest version in docker on Ubuntu 20.04 for quite a while...and it&#39;s been running fine... Now yesterday, after watchtower update, it failed with error alter table \`po...![](https://github.com/fluidicon.png)GitHubdocker-library![](https://opengraph.githubassets.com/7f2cb75554a883564624331deb84ac2d3c5d49a60743d43bab7970420b42de2d/docker-library/ghost/issues/288)](https://github.com/docker-library/ghost/issues/288?ref=yinguobing.com#issuecomment-1046163905)

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