我有这段代码但不起作用:
<?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");
}
}
我在手机中的新字段告诉电话中添加了信息。
谢谢