ghost博客从4.x版本升级5.x问题记录

ghost博客从4.x版本升级5.x问题记录
Photo by Francisco De Legarreta C. / Unsplash

我的博客最近两天从v4升级到了v5,我个人体验下来,主要变化如下:

  • 原生支持评论(还是不咋好用,后台看不到评论列表,得去文章里看)
  • 原生支持文章搜索
  • 好像还多了一个公告栏

具体我还没深度体验,先写个问题总结帖,把我遇到的问题分享下

问题1: foreign key constraint

报错内容:

alter table `subscriptions` modify  `tier_id` varchar(24) not null  - Cannot change column 'tier_id': used in a foreign key constraint 'subscriptions_tier_id_foreign'

解决方法:

  1. 如果你有mysql的root帐号权限,那你可以用root帐号登陆到mysql,然后执行
SET GLOBAL FOREIGN_KEY_CHECKS=0;

先把FOREIGN_KEY_CHECKS设置临时关闭掉,再去执行ghost update等待升级完成

2. 如果你没有root权限,那可以像我一样,修改一下代码

cd ghost博客的根目录
vi ./versions/5.53.1/core/server/data/migrations/versions/5.20/2022-10-18-05-39-drop-nullable-tier-id.js

# 找到这行
module.exports = createDropNullableMigration('subscriptions', 'tier_id');
# 替换成这样
module.exports = createDropNullableMigration('subscriptions', 'tier_id', {disableForeignKeyChecks:1});

同样替换完成后,继续执行ghost update,应该就可以升级完成了

问题2: 邮件发送失败

报错内容:

NAME: EmailError
CODE: EENVELOPE
MESSAGE: Failed to send email. Reason: Mail command failed: 436 "MAIL FROM" doesn't conform with authentication [@sm060104] (Auth Account:noreply@mail.quzone.cn|Mail Account:noreply@blog.quzone.cn).

我用的是阿里云的邮箱服务,分享一下我的配置:

 "mail": {
        "from": "'乐心的博客' <noreply@mail.quzone.cn>",
        "transport": "SMTP",
        "options": {
            "host": "smtpdm.aliyun.com",
            "secure": true,
            "port": 465,
            "auth": {
                "user": "noreply@mail.quzone.cn",
                "pass": "xxxxxxxx"
            }
        }
    },

这个报错是由于ghost代码里写死了邮箱发送帐号为 <noreply@博客域名>,所以无论你在配置文件里怎么配,他都是用这个写死的域名。。这是个很不能理解的问题。。。

解决方法:

cd ghost博客的根目录
vi current/core/server/services/mail/GhostMailer.js

# 找到这一行
const address = requestedFromAddress || configAddress;
# 替换为这一行
const address = configAddress || requestedFromAddress;

# 保存退出 重启一下
ghost restart