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.
Du musst angemeldet sein, um einen Kommentar abzugeben.
Dies kann ein älterer post, aber mittlerweile ist das problem gelöst und eigentlich Teil der aktuellen Dokumentation.
Sehen http://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html#container-aware-migrations
Müssen Sie Ihre änderungen in der
postUp()
Methode - dieaddSql()
- Anweisungen werden ausgeführt, nachdemup()
- Methode abgeschlossen ist, so dass Ihre neue Zeilen (d.h. tellphone) sind nicht verfügbar, während derup()
Methode!