我在 CakePHP 4 上的迁移出了什么问题?
我对我的应用程序的数据库结构进行了一些较小的更改,并将新列添加到一个名为绘图的表中。这是迁移之一 -
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过在文档中稍微进一步阅读 - 迁移和部署。
我需要运行
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