Reputation: 110
I'm trying to learn the basics of Symfony, and have come across a problem that baffles me.
I'm trying to write Data to a SQL Table, following (mostly) the instructions from the documentation ( http://symfony.com/doc/current/book/doctrine.html ). I created an entity via
$ php bin/console doctrine:generate:entity
and it is mapped to my DB Table correctly, I can read and write, no problem. After that I added a column to my table and the corresponding lines to my Entity:
/**
* @var string
*
* @ORM\Column(name="User_Credentials", type="text")
*/
private $userCredentials;
Then I tried creating the setters and getters, but no changes were made, just a backup of my Entity. So I added getter and setter myself, but when attempting to write to the DB the corresponding column is ommited, remaining empty. No errors are given. I checked and re-checked for typos or other sytax errors, but could not find any. When doing
$ php bin/console doctrine:schema:update --dump-sql
I get
ALTER TABLE st_users DROP User_Credentials;
So it seems my Column is completely ignored. I cleared the cache repatedly, which changed nothing. I am, obviously, lost. Any hint as to the right path will be appreciated.
Thank you.
Upvotes: 0
Views: 6495
Reputation: 1674
I added a column to my table and the corresponding lines to my Entity
The concept of Symfony is to add column only to entity, but not to table itself.
Then, when you execute
php bin/console doctrine:schema:update --force
Symfony would detect that you have a new column and it will add column to the table automatically.
PS. Regarding clearing a cache. In case apc cache is enabled in Symfony - you also need to restart Apache or php-fpm process. Otherwise it will ignore new annotations.
Upvotes: 1
Reputation: 110
Well, this is embarassing...
Anyway, if someone else is having the same problem: I had a Tab before the '@ORM\Column' annotation, and it seems the parser can't handle that. Deleting the tab and adding a space did the trick.
Mert's answer is correct anyway, so I will mark it as the right answer.
Upvotes: 4
Reputation: 1071
You can use DoctrineMigrationsBundle for this operations. This bundle will manage your database operations. (Drop, Alter, Create etc.)
Anyway, when you add a new column you can try this: php app/console doctrine:schema:update --force
Upvotes: 6