【发布时间】:2018-07-09 05:19:53
【问题描述】:
我有一个看起来像这样的 Doctrine 迁移:
<?php
namespace Application\Migrations;
use Doctrine\ORM\Mapping\PushNotification;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20180123103147 extends AbstractMigration implements ContainerAwareInterface
{
private $container;
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$em = $this->container->getDoctrine()->getManager();
$tableName = $em->getClassMetadata('AppBundle:PushNotification')->getTableName();
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE '.$tableName.' ADD COLUMN last_offset int(11) ');
$this->addSql('ALTER TABLE '.$tableName.' ADD COLUMN failure_count int(11) ');
$this->addSql('ALTER TABLE '.$tableName.' ADD COLUMN is_sent int(11) ');
$this->addSql('ALTER TABLE '.$tableName.' ADD COLUMN send_date datetime ');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
$em = $this->container->getDoctrine()->getManager();
$tableName = $em->getClassMetadata('AppBundle:PushNotification')->getTableName();
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE '.$tableName.' DROP COLUMN last_offset ');
$this->addSql('ALTER TABLE '.$tableName.' DROP COLUMN failure_count ');
$this->addSql('ALTER TABLE '.$tableName.' DROP COLUMN is_sent ');
$this->addSql('ALTER TABLE '.$tableName.' DROP COLUMN send_date ');
}
}
...在运行迁移时,我收到一条错误消息,指出 Declaration of Application\Migrations\Version20180123103147::setContainer() must be compatible with Symfony\Component\DependencyInjection\ContainerAwareInterface::setContainer(Symfony\Component\DependencyInjection\ContainerInterface $container = NULL)
这个错误似乎不合适,因为我直接从相关接口复制了方法签名。
这里有没有明显遗漏的代码?
【问题讨论】:
-
错误是抱怨方法签名,从我看到你没有导入
ContainerInterface因此类型不匹配
标签: php symfony doctrine database-migration