问题
Something very strange happened to my right now...
I use the newest symfony CLI tool and created a project and an entity which has a field "name". When i update or migrate the schema, only the column "id" is generated.
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
The created entity:
<?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;
}
}
The created migration (only column id is generated):
<?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');
}
}
I have a mysql server running at localhost:
Server version: 5.7.28-0ubuntu0.18.04.4 (Ubuntu)
The connection string looks like this:
DATABASE_URL=mysql://user:password@127.0.0.1:3306/test?serverVersion=5.7
Also php bin/console doctrine:schema:update --force
instead of migration gives me the same result.
Any suggestion why this is happening?
回答1:
After a php bin/console cache:clear
everything worked as expected.
来源:https://stackoverflow.com/questions/59069167/symfony-5-0-makemigration-or-doctrineschemaupdate-force-only-creates-id-co