我现在发生了非常奇怪的事情...
我使用最新的symfony CLI工具,并创建了一个项目和一个具有“名称”字段的实体。当我更新或迁移架构时,仅生成“ id”列。
Symfony CLI version v4.11.2 (c) 2017-2019 Symfony SAS
$ symfony new --full test
$ cd test
$ php bin/console doctrine:database:create
$ php bin/console make:entity Test
$ php bin/console make:migration
$ php bin/console doctrine:migrations:migrate
创建的实体:
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\TestRepository")
*/
class Test
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
}
创建的迁移(仅生成列ID):
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20191127110625 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// 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('CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
}
public function down(Schema $schema) : void
{
// 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('DROP TABLE test');
}
}
我有一个在本地主机上运行的mysql服务器:
Server version: 5.7.28-0ubuntu0.18.04.4 (Ubuntu)
连接字符串如下所示:
DATABASE_URL=mysql://user:[email protected]:3306/test?serverVersion=5.7
也php bin/console doctrine:schema:update --force
而不是迁移给了我相同的结果。
任何建议为什么会这样?
php bin/console cache:clear
之后,一切都按预期进行。