Verwenden EntityManager in Migrationen-Datei

Ich habe diesen code der aber nicht funktioniert:

<?php

namespace Application\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration,
    Doctrine\DBAL\Schema\Schema;

/**
 * Auto-generated Migration: Please modify to your need!
 */
class Version20131021150555 extends AbstractMigration
{

    public function up(Schema $schema)
    {
        //this up() migration is auto-generated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'.");

        $this->addSql("ALTER TABLE person ADD tellphone LONGTEXT DEFAULT NULL");

        $em = $em = $this->getDoctrine()->getEntityManager();
        $persons = $em->getRepository('AutogestionBundle:Person')->fetchAll();

        foreach($persons as $person){
            $person->setTellPhone($person->getCellPhone());
            $em->persist($person);                                                                            
        }
        $em->flush(); 
    }

    public function down(Schema $schema)
    {
        //this down() migration is auto-generated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'.");

        $this->addSql("ALTER TABLE person DROP tellphone");
    }
}

Ich add info in Handy in ein neues Feld tellphone.

Dank

  • Was meinst du mit 'funktioniert nicht'. Wie werden diese Methoden genannt? Was ist die erwartete und die aktuelle Ergebnis?
  • Diese Zeile bekomme Fehler $em = $em = $this->getDoctrine()->getEntityManager(); muss ich verwenden EntityManager in dieser Datei. Dank
  • Es ist nicht arbeiten, weil Sie Aufruf $this->getDoctrine(), AbstractMigration Klasse hat die nicht, diese Methode.
InformationsquelleAutor Zarpele | 2013-10-21
Schreibe einen Kommentar