Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 367 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Symfony doctrine:schema:update not working

#1

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 !
Reply

#2
Try

php app/console doctrine:schema:update --force

this is update your database schema with entity
Reply

#3
Type `php app/console help doctrine:schema:update` in CLI

--dump-sql Dumps the generated SQL statements to the screen (does no
t execute them).

...

--force Causes the generated SQL statements to be physically exec
uted against your database.

So try the `--force` instead of `--dump-sql`.

And here is the command for cache clearing :

php app/console cache:clear

Don't forget to use the `help` keyword before a command namespace in order to get the help message for that command.

Hope it helps
Reply

#4
I found the solution :
I did not see before but there was a doctrine folder in src\Too\ConfigAppBundle\Resources\config containing a file called ConfigApp.orm.yml :

Too\ConfigAppBundle\Entity\ConfigApp:
type: entity
table: null
repositoryClass: Too\ConfigAppBundle\Entity\ConfigAppRepository
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
nom:
type: string
length: '100'
nomSlug:
type: string
length: '100'
email:
type: string
length: '150'
telephone:
type: string
length: '15'
cree_le:
type: datetime
length: null
modifie_le:
type: datetime
length: null
lifecycleCallbacks: { }

I deleted this folder and now updating the schema works again.

Surely I did something to generate this doctrine folder but I don't know what it was - if someone could tell me how this stuff is generated - and why ?
Reply

#5
i think its beacause of the doctrine:mapping:import command. This command stores the schema of an existing database into .orm.xml files. Probebly you execute this command.

I had the same issue, coast me a lot of time to find out.
Reply

#6
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

Reply

#7
Try to use YAML instead of the default annotation when you run

php app/console doctrine:generate:entity

Or instead of running

app/console doctrine:schema:update --force

You can just manually create your MySql table which is a very tedious task

Reply

#8
It is possible that you forget to enable Doctrine auto mapping;

orm:
#auto_mapping: true

If auto mapping is disabled (or commented like above) , you should register Entities of each bundle manually.

orm:
entity_managers:
default:
mappings:
AcmeHelloBundle: ~
Reply

#9
Because I was using `.orm.yml`-mapping I had the issue that I created the `doctrine`-folder, in which the `yml` mappings were present, under the wrong path, so I fixed it by moving the `doctrine`-folder to the the `config` folder:
`...\BundleName\Resources\config\doctrine\MyEntity.orm.yml`
Reply

#10
Though some of the answers given by @rai and others are correct, one more suggestion for Symfony version is equal to or above 3.0 please use bin/console instead app/console, as shown below,

bin/console doctrine:schema:update --force
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through