2

I`m trying to change a table name with doctrine migrations.

Example table name is model and I want to change it to new_model.

/**
 * Class Model
 *
 * @package AppBundle\Entity
 *
 * @ORM\Table(name="new_model")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\ModelRepository")
 * @ORM\HasLifecycleCallbacks()
 */
class Model
{
......

 * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Product", inversedBy="products", fetch="EAGER", cascade={"persist"})
 * @ORM\JoinColumn(name="product_id", referencedColumnName="id", nullable=false)   
private $brand;

.......

To change to column name manually with migration script, I used:

 $this->addSql('ALTER TABLE model RENAME new_model');

After running the migration the relations(join columns) are not changed and still reference to the old columnname. I also cleared the cache.

Does someone know how I can change a table name and the foreign key without loosing the relation data?

Erik
  • 427
  • 6
  • 14

1 Answers1

2

:(

The normal way of clearing cache was missing the mapping for doctrine.

After running: php bin/console d:c:clear-metadata

It was working again.

Erik
  • 427
  • 6
  • 14