我在 CakePHP 4 上的迁移出了什么问题?

发布于 2025-01-19 11:02:26 字数 676 浏览 5 评论 0原文

我对我的应用程序的数据库结构进行了一些较小的更改,并将新列添加到一个名为绘图的表中。这是迁移之一 -

declare(strict_types=1);

use Migrations\AbstractMigration;

class AddGarageToPlots extends AbstractMigration
{
    public function change()
    {
        $table = $this->table('plots');
        $table->addColumn('garage', 'string', [
            'default' => null,
            'limit' => 255,
            'null' => true,
        ]);
        $table->update();
    }
}

当我应用迁移时,似乎没有错误:没有错误,如果我直接连接到数据库,我可以在数据库中看到新列,但是当我尝试访问新字段中的数据时视图使用,例如<?= $ plot-> 它始终返回null,即使我已经通过直接连接填充了此字段。

我还有其他需要做的事情,还是我在这里缺少的,或者有某种方法可以检查迁移是否像架构文件一样正常工作?

I've applied a couple of minor changes to the database structure for my app, adding new columns to a table called Plots. This is one of the migrations -

declare(strict_types=1);

use Migrations\AbstractMigration;

class AddGarageToPlots extends AbstractMigration
{
    public function change()
    {
        $table = $this->table('plots');
        $table->addColumn('garage', 'string', [
            'default' => null,
            'limit' => 255,
            'null' => true,
        ]);
        $table->update();
    }
}

When I apply the migration it seems to run fine: there are no errors and I can see the new column in the database if I connect directly to it but when I try to access data in the new field in a view using, for example, <?= $plot->garage ?> it consistently returns null even though I have populated this field via the direct connection.

Is there something else I need to do that I'm missing here or is there some way I can check that the migration has worked properly like a schema file somewhere?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我闹别瞎闹 2025-01-26 11:02:26

通过在文档中稍微进一步阅读 - 迁移和部署

我需要运行bin/cake schema_cache clear

Found the answer to my own question by reading slightly further in the documentation - migrations and deployment.

I needed to run bin/cake schema_cache clear

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文