为什么我得到“表已存在”?

时间:2019-08-05 13:09:36

标签: symfony doctrine migration

我正在尝试迁移到数据库,但是我得到了:

  

名称为“ compteur_honore.ingredientsrecettes”的表已经存在。

我检查了自己的实体,但没有看到任何错误,必须有一个错误,但我找不到...

/**
 *
 * @ORM\Table(name="ingredientsRecettes", indexes={@ORM\Index(name="recette_id", columns={"recettes_id"}), @ORM\Index(name="ingredients_id", columns={"ingredients_id"})})
 * @ORM\Entity(repositoryClass="App\Repository\IngredientsrecettesRepository")
 */
class Ingredientsrecettes
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var \Recettes
     *
     * @ORM\ManyToOne(targetEntity="Recettes")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="recettes_id", referencedColumnName="id")
     * })
     */
    private $recettes_id;

    /**
     * @var \Ingredients
     *
     * @ORM\ManyToOne(targetEntity="Ingredients")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="ingredients_id", referencedColumnName="id")
     * })
     */
    private $ingredients_id;

    /**
     * @ORM\Column(name="quantite", type="float", nullable=false)
     */
    private $quantite;

    /**
     * @return mixed
     */
    public function getQuantite()
    {
        return $this->quantite;
    }

    /**
     * @param mixed $quantite
     */
    public function setQuantite($quantite): void
    {
        $this->quantite = $quantite;
    }

    /**
     * @return int
     */
    public function getId(): int
    {
        return $this->id;
    }

    /**
     * @param int $id
     */
    public function setId(int $id): void
    {
        $this->id = $id;
    }

    /**
     * @return \Recettes
     */
    public function getRecette_id(): ?Recettes
    {
        return $this->recettes_id;
    }


    public function setRecettes_id(?Recettes $recettes_id): self
    {
        $this->recettes_id = $recettes_id;
    }

    public function getIngredients(): ?Ingredients
    {
        return $this->ingredients_id;
    }


    public function setIngredient(?Ingredients $ingredient): self
    {
        $this->ingredient = $ingredient;
    }
}
class Recettes
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;


    /**
     * @ORM\ManyToMany(targetEntity=Ingredients::class)
     * @ORM\JoinTable(name="ingredientsRecettes")
     * joinColumns={@JoinColumn(name="ingredients_id", referencedColumnName="id")},
     * inverseJoinColumns={@JoinColumn(name="recettes_id", referencedColumnName="id")}
     *
     */
    protected $ingredients;

    public function __construct()
    {
        $this->ingredients = new ArrayCollection();
    }

    /**
     * @var string
     *
     * @ORM\Column(name="nom", type="text", length=65535, nullable=false)
     */
    private $nom;

    /**
     * @return string
     */
    public function getNom(): string
    {
        return $this->nom;
    }

    /**
     * @param string $nom
     */
    public function setNom(string $nom): void
    {
        $this->nom = $nom;
    }

    /**
     * @return int
     */
    public function getId(): int
    {
        return $this->id;
    }

    /**
     * @param int $id
     */
    public function setId(int $id): void
    {
        $this->id = $id;
    }

    /**
     * @return mixed
     */
    public function getIngredients()
    {
        return $this->ingredients;
    }

    /**
     * @param mixed $ingredients
     */
    public function setIngredients($ingredients): void
    {
        $this->ingredients = $ingredients;
    }

    public function addIngredient(Ingredients $ingredient): self
    {
        if (!$this->ingredients->contains($ingredient)) {
            $this->ingredients[] = $ingredient;
        }

        return $this;
    }

    public function removeIngredient(Ingredients $ingredient): self
    {
        if ($this->ingredients->contains($ingredient)) {
            $this->ingredients->removeElement($ingredient);
        }

        return $this;
    }

}
/**
 * Ingredients
 *
 * @ORM\Table(name="ingredients", indexes={@ORM\Index(name="unite_mesure", columns={"unitesMesure"})})
 * @ORM\Entity
 */
class Ingredients
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="nom", type="text", length=65535, nullable=false)
     */
    private $nom;

    /**
     * @var \Unitesmesure
     *
     * @ORM\ManyToOne(targetEntity="Unitesmesure")
     * @ORM\JoinColumns({
     * @ORM\JoinColumn(name="unitesMesure", referencedColumnName="id")
     * })
     */
    private $unitesmesure;

    /**
     * @return int
     */
    public function getId(): int
    {
        return $this->id;
    }

    /**
     * @param int $id
     */
    public function setId(int $id): void
    {
        $this->id = $id;
    }

    /**
     * @return string
     */
    public function getNom(): string
    {
        return $this->nom;
    }

    /**
     * @param string $nom
     */
    public function setNom(string $nom): void
    {
        $this->nom = $nom;
    }

    public function getUnitesmesure(): ?Unitesmesure
    {
        return $this->unitesmesure;
    }

    public function setUnitesmesure(?Unitesmesure $unitesmesure): self
    {
        $this->unitesmesure = $unitesmesure;

        return $this;
    }
}

当我使用命令php bin/console doctrine:migrations:diff时,收到消息:

  

名称为“ compteur_honore.ingredientsrecettes”的表已经存在。

这是迁移

final class Version20190805125202 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('ALTER TABLE boulangerie DROP FOREIGN KEY boulangerie_ibfk_2');
        $this->addSql('CREATE TABLE recettes_ingredients (recettes_id INT NOT NULL, ingredients_id INT NOT NULL, INDEX IDX_33E6DB8E3E2ED6D6 (recettes_id), INDEX IDX_33E6DB8E3EC4DCE (ingredients_id), PRIMARY KEY(recettes_id, ingredients_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
        $this->addSql('ALTER TABLE recettes_ingredients ADD CONSTRAINT FK_33E6DB8E3E2ED6D6 FOREIGN KEY (recettes_id) REFERENCES recettes (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE recettes_ingredients ADD CONSTRAINT FK_33E6DB8E3EC4DCE FOREIGN KEY (ingredients_id) REFERENCES ingredients (id) ON DELETE CASCADE');
        $this->addSql('DROP TABLE boulangerie');
        $this->addSql('DROP TABLE recettesPerso');
        $this->addSql('DROP TABLE rememberme_token');
        $this->addSql('ALTER TABLE ingredientsRecettes CHANGE quantite quantite DOUBLE PRECISION NOT NULL');
        $this->addSql('ALTER TABLE ingredientsRecettes RENAME INDEX idrecette TO recette_id');
        $this->addSql('ALTER TABLE ingredientsRecettes RENAME INDEX idingredient TO ingredients_id');
    }

    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('CREATE TABLE boulangerie (id INT AUTO_INCREMENT NOT NULL, recette INT DEFAULT NULL, nom TEXT NOT NULL COLLATE utf8_unicode_ci, poids DOUBLE PRECISION NOT NULL, recettePerso INT DEFAULT NULL, INDEX recette_perso (recettePerso), INDEX recette (recette), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB COMMENT = \'\' ');
        $this->addSql('CREATE TABLE recettesPerso (id INT AUTO_INCREMENT NOT NULL, idUtilisateur INT DEFAULT NULL, nom TEXT NOT NULL COLLATE utf8_unicode_ci, ingredients INT NOT NULL, ingredientsPerso INT NOT NULL, INDEX ingredientsPerso (ingredientsPerso), INDEX idUtilisateur (idUtilisateur, ingredients), INDEX ingredients (ingredients), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB COMMENT = \'\' ');
        $this->addSql('CREATE TABLE rememberme_token (series CHAR(88) NOT NULL COLLATE utf8_unicode_ci, value CHAR(88) NOT NULL COLLATE utf8_unicode_ci, lastUsed DATETIME NOT NULL, class VARCHAR(100) NOT NULL COLLATE utf8_unicode_ci, username VARCHAR(200) NOT NULL COLLATE utf8_unicode_ci, UNIQUE INDEX series (series), PRIMARY KEY(series)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB COMMENT = \'\' ');
        $this->addSql('ALTER TABLE boulangerie ADD CONSTRAINT boulangerie_ibfk_2 FOREIGN KEY (recettePerso) REFERENCES recettesperso (id)');
        $this->addSql('ALTER TABLE boulangerie ADD CONSTRAINT boulangerie_ibfk_3 FOREIGN KEY (recette) REFERENCES recettes (id)');
        $this->addSql('DROP TABLE recettes_ingredients');
        $this->addSql('ALTER TABLE ingredientsRecettes CHANGE quantite quantite DOUBLE PRECISION DEFAULT NULL');
        $this->addSql('ALTER TABLE ingredientsRecettes RENAME INDEX recette_id TO idRecette');
        $this->addSql('ALTER TABLE ingredientsRecettes RENAME INDEX ingredients_id TO idIngredient');
    }
}

0 个答案:

没有答案