Zend Basic Tutorial
Zend Forms
Zend Database
Zend Advanced
ALTER TABLE
in Doctrine Migrations?In Doctrine, ALTER TABLE
refers to modifying an existing table schema using a new migration file. Common use cases:
status
boolean column to the user
tableUpdate User.php
: in (module\Application\src\Entity\User.php)
namespace Application\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="user") */ class User { /** @ORM\Id @ORM\GeneratedValue @ORM\Column(type="integer") */ private $id; /** @ORM\Column(type="string", length=255) */ private $email; /** @ORM\Column(type="string", length=255) */ private $password; /** * @ORM\Column(type="boolean", options={"default" : false}) */ private $status; }
Run this in terminal:
php vendor/bin/doctrine-migrations diff
This creates a file like:
public function up(Schema $schema): void { $this->addSql('ALTER TABLE user ADD status TINYINT(1) DEFAULT 0 NOT NULL'); } public function down(Schema $schema): void { $this->addSql('ALTER TABLE user DROP status'); }
php vendor/bin/doctrine-migrations migrate
Your user
table now has a status
column of type boolean
.
you have a user
table with a column status
that is currently boolean , and you want to change it to string.
Before:
/** * @ORM\Column(type="boolean", options={"default" : false}) */ private $status;
After:
/** * @ORM\Column(type="string", length=10) */ private $status;
Run this in terminal:
php vendor/bin/doctrine-migrations diff
php vendor/bin/doctrine-migrations migrate