【发布时间】:2017-12-22 06:19:18
【问题描述】:
我继承了一个没有迁移的 Symfony 3 项目。
在documentation 之后,我将 Doctrine Migrations Bundle 添加到 Symfony。
$ composer require doctrine/doctrine-migrations-bundle "^1.0"
将配置添加到 config.yml
doctrine_migrations:
dir_name: "%kernel.root_dir%/DoctrineMigrations"
namespace: Application\Migrations
table_name: migration_versions
name: Application Migrations
然后将加载器添加到appKernel.php
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
控制台现在将教义:迁移:* 显示为可用功能,因此我随后生成了我的迁移文件
php bin/console doctrine:migrations:generate
Generated new migration class to "/path/to/project/app/DoctrineMigrations/Version20100621140655.php"
然后继续关注Doctrine migrations documentation:
public function up(Schema $schema)
{
// alter my table
$options = ['fields' => ['type_id']];
$schema->addIndex('advertiser', 'idx_type_id', $options);
...
}
现在,当我运行迁移时:
Migrating up to 20170714165306 from 20170714155549
++ migrating 20170714165306
[Symfony\Component\Debug\Exception\UndefinedMethodException]
Attempted to call an undefined method named "addIndex" of class "ProxyManagerGeneratedProxy\__PM__\Doctrine\DBAL\Schema\Schema\Generatedaca9b50393335f8354881e485c485329".
现在,当我遇到该错误时,我搜索并找到了 ocramius/ProxyManager。我用
安装了它composer require ocramius/proxy-manager "^2.0"
还是同样的错误。
当然,在大多数 Doctrine Migrations 文档中,我主要看到 addSql( 'ALTER TABLE ...') 类型语句,但我想使用包装方法 addIndex、removeIndex 等。
有人能解释一下如何让这些功能发挥作用吗?
【问题讨论】:
-
引用的文档看起来不像
doctrine-migrations-bundle包,但是试试这个$schema->getTable('table_name')->addIndex(...)看看addIndex()签名。
标签: php symfony doctrine-orm database-migration