在Ubuntu 20.04、MYSQL 8.0下Ghost v4 版本更新深坑及实战解决方法
前天晚上手贱,看到 Ghost 出到了 v4.3.1,想着更新一下应该没事吧。毕竟是小版本更新。
实际摔深坑里了。以为5分钟搞定实际花了差不多1天时间。趁现在还记得解决步骤赶紧写个Blog记录以备用并分享给同伴😂。
从4.2.1更新到4.3.1版本错误如下:
A GhostError occurred.
Message: Ghost was able to start, but errored during boot with: alter table `members_products` add constraint `members_products_member_id_foreign` foreign key (`member_id`) references `members` (`id`) on delete CASCADE - UNKNOWN_CODE_PLEASE_REPORT: Referencing column 'member_id' and referenced column 'id' in foreign key constraint 'members_products_member_id_foreign' are incompatible.
Help: Error occurred while executing the following migration: 02-add-members-products-table.js
Suggestion: journalctl -u ghost_hansendong-me -n 50
Debug Information:
OS: Ubuntu, v20.04.2 LTS
Node Version: v12.16.1
Ghost Version: 4.3.1
Ghost-CLI Version: 1.16.3
Environment: production
Command: 'ghost restart'
Additional log info available in: /home/blog/.ghost/logs/ghost-cli-debug-2021-04-22T15_14_23_687Z.log
Try running ghost doctor to check your system for known issues.
You can always refer to https://ghost.org/docs/ghost-cli/ for troubleshooting.
然后Google相关关键词,虽然有类似案例但都没有得到准确的答案。去他们开发者论坛看了看,也有高度类似的案例,官方人员有回复提供解决方案(可能是数据库字符集兼容问题),仍然没有得到解决。
我也试得根据官方人员提供方案做测试,均没有解决。想着是不是依赖软件版本太低,但更新到最新版本还是不行(如下)。
A GhostError occurred.
Message: Ghost was able to start, but errored during boot with: alter table `members_products` add constraint `members_products_member_id_foreign` foreign key (`member_id`) references `members` (`id`) on delete CASCADE - UNKNOWN_CODE_PLEASE_REPORT: Referencing column 'member_id' and referenced column 'id' in foreign key constraint 'members_products_member_id_foreign' are incompatible.
Help: Error occurred while executing the following migration: 02-add-members-products-table.js
Suggestion: journalctl -u ghost_hansendong-me -n 50
Debug Information:
OS: Ubuntu, v20.04.2 LTS
Node Version: v14.16.1
Ghost Version: 4.3.1
Ghost-CLI Version: 1.16.3
Environment: production
Command: 'ghost restart'
Additional log info available in: /home/blog/.ghost/logs/ghost-cli-debug-2021-04-22T19_34_36_395Z.log
Try running ghost doctor to check your system for known issues.
You can always refer to https://ghost.org/docs/ghost-cli/ for troubleshooting.
在论坛发帖也没有得到有用的回复,无奈只好用命令行导出Blog数据库及下载照片、主题文件夹作为备份。这时已经是昨天凌晨4点多,就去睡觉了。
mysqldump -uusername -ppassword databasename > /var/www/ghost/databasename.sql
起床后,把该忙的忙完了,继续折腾。想着把VPS重装系统,系统选择Ubuntu 18.04 LTS,Ghost选择最后正常使用的4.2.1,导入数据库看看。
没想到是那个服务商的VPS重装系统后无法更新系统,懒着研究了。换成Linode一切正常,系统选择Ubuntu 20.04,按照 官方教程 全新安装了一遍,Ghost版本已经是4.3.2了,各项功能一切正常。但尝试导入SQL数据库文件仍然提示相同错误。难道Blog只能重新开始了吗?不甘心。这个VPS已经搭建好了,不想推倒重来了。
于是临时新开个VPS,系统选择Ubuntu 18.04 LTS,重复上面教程。但在Run the install process这一步时候,在后面加上你要安装的版本号:
ghost install v4.2.1
这样就可以安装指定的版本了。之后我尝试导入数据库SQL文件:
mysql -uusername -ppassword databasename < /var/www/ghost/databasename.sql;
成功!!!
进入后台在左下角右侧设置--Labs--Export your content导出文章和设置数据。在这个Blog后台成功导入。呼~,7年心血又完整回来了!把之前的备份的图片和主题文件夹通过SSH软件上传对应的位置。打开文章看看正常显示。
我的Blog完美复活!!!这次学乖了,加了每月2刀自动备份的服务。