Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony doctrine:schema:update not working

I have a strange problem : I have an application symfony 2.3 (with sonata user) I created a bundle with one entity - the entity was created without a problem then I had to modify the entity and now it seems to be impossible to modify the schema :

To see what happens I increased all the string lengths with +1

The entity code (with annotations) :

namespace Too\ConfigAppBundle\Entity;

use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;

/**
 * ConfigApp
 *
 * @ORM\Table(name="ConfigApp")
 * @ORM\Entity(repositoryClass="Too\ConfigAppBundle\Entity\ActiviteRepository")
 */
class ConfigApp
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string $nom
     *
     * @ORM\Column(name="nom", type="string", length=101, unique=true)
     */
    private $nom;

    /**
     * @var string $nomSlug
     *
     * @Gedmo\Slug(fields={"nom"}, updatable=true, separator="_")
     * @ORM\Column(name="nomSlug", type="string", length=101, nullable=true)
     */
    private $nomSlug;

    /**
     * @var string $email
     *
     * @ORM\Column(name="email", type="string", length=151)
     */
    private $email;

    /**
     * @var string $telephone
     *
     * @ORM\Column(name="telephone", type="string", length=16)
     */
    private $telephone;

    /**
     * @var datetime $cree_le
     *
     * @Gedmo\Timestampable(on="create")
     * @ORM\Column(name="cree_le", type="datetime")
     */
    private $cree_le;

    /**
     * @var datetime $modifie_le
     *
     * @Gedmo\Timestampable(on="update")
     * @ORM\Column(name="modifie_le", type="datetime")
     */
    private $modifie_le;

    ...

Now see the result of :

php app/console doctrine:schema:update --dump-sql

CREATE TABLE ConfigApp (id INT AUTO_INCREMENT NOT NULL, nom VARCHAR(100) NOT NULL, nomSlug VARCHAR(100) NOT NULL, email VARCHAR(150) NOT NULL, telephone VARCHAR(15) NOT NULL, cree_le DATETIME NOT NULL, modifie_le DATETIME NOT NULL, PRIMARYKEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB

None of the new length is taken in account : for example the field nom should have length=101, but the dump-sql gives nom VARCHAR(100) !

Could anyone try to figure out whats going wrong ? Thanks !

EDIT : I tried to clear the cache before with : * php app/console doctrine:cache:clear-metadata * php app/console cache:clear * by deleting all content in cache folders

I also tried --dump-sql and --force.

This changes nothing at all. Please any hint would be welcome !

like image 643
G. Trennert Avatar asked Nov 11 '13 02:11

G. Trennert


1 Answers

I just ended up on the exact same issue: schema doesn't update.

Note that --force returns exactly the same thing as --dump-sql, the only difference is that --force runs the SQL against the database.

Although, in my case, the issue wasn't because of the .orm.xml file. It was because I've set this in the config_dev.xml:

doctrine:
orm:
    metadata_cache_driver:
        type: memcached
        host: localhost
        port: 11211
        instance_class: Memcached
    query_cache_driver:
        type: memcached
        host: localhost
        port: 11211
        instance_class: Memcached
    result_cache_driver:
        type: memcached
        host: localhost
        port: 11211
        instance_class: Memcached

Even when I issue an often salvatory:

php app/console cache:clear

the memcached data isn't flushed. So I had to restart memcached, then everything was up and running again!

So thanks for your question, it led me to the right spot in my case.

UPDATE: as Phil suggested above, running this command does the trick too:

php app/console doctrine:cache:clear-metadata
like image 167
Yvan Avatar answered Oct 06 '22 00:10

Yvan