问题描述
我有一个奇怪的问题:
我有一个应用程序symfony 2.3(有奏鸣曲用户)
我创建了一个具有一个实体的捆绑包-该实体创建时没有问题
,我有修改实体,现在似乎无法修改架构:
看看会发生什么,我将所有字符串长度都增加了+1
实体代码(带有注释):
命名空间Too\ConfigAppBundle\Entity;
使用Gedmo\映射\Annotation为Gedmo;
使用Doctrine\ORM\映射作为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)
* /
私人$ id;
/ **
* @var string $ nom
*
* @ ORM\Column(name = nom,type = string,长度= 101,unique = true)
* /
私人$ nom;
/ **
* @var string $ nomSlug
*
* @ Gedmo\Slug(fields = { nom},可更新= true,分隔符= _)
* @ ORM\Column(name = nomSlug,type = string,length = 101,nullable = true)
* /
private $ nomSlug;
/ **
* @var字符串$ email
*
* @ ORM\Column(name = email,type = string,长度= 151)
* /
私人$ email;
/ **
* @var string $ telephone
*
* @ ORM\Column(name = telephone,type = string,length = 16)
* /
私人$电话;
/ **
* @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;
...
现在查看结果:
php应用程序/控制台学说:schema:update --dump-sql
创建表ConfigApp(id INT AUTO_INCREMENT NOT NULL,nom VARCHAR(100)NOT NULL,nomSlug VARCHAR(100)NOT NULL,电子邮件VARCHAR(150)NOT NULL,电话VARCHAR(15)NOT NULL,cree_le DATETIME NOT NULL,modifie_le DATETIME NOT NULL,PRIMARYKEY(id))默认字符集utf8集合utf8_unicode_ci ENGINE = InnoDB
没有考虑新长度:$ b $例如,b字段nom的长度应为101,
,但dump-sql给出nom VARCHAR(100)!
有人可以试着弄清楚是什么吗出问题了吗?
谢谢!
编辑:
我之前尝试通过以下方式清除缓存:
* php app / console doctrine:cache:clear -metadata
* php应用程序/控制台缓存:通过删除缓存文件夹中的所有内容清除
*
我还尝试了--dump-sql和--force。
这完全没有改变。
请欢迎提供任何提示!
我刚遇到了一个完全相同的问题:模式没有更新。
请注意,--force返回与--dump-sql完全相同的东西,唯一的区别是--force对数据库运行SQL。 / p>
虽然,就我而言,问题不是由于.orm.xml文件引起的。这是因为我已经在config_dev.xml中进行了设置:
主义:
orm:
metadata_cache_driver:
类型:memcached
主机:localhost
端口:11211
instance_class:Memcached
query_cache_driver:
类型:memcached
主机:localhost
端口:11211
instance_class:Memcached
result_cache_driver:
type:memcached
主机:localhost
port:11211
instance_class:Memcached
即使我发出经常得救的东西:
php应用程序/控制台缓存:清除
内存缓存数据为 t脸红了。因此,我不得不重新启动memcached,然后一切都重新启动并运行!
因此,感谢您的提问,这使我找到了正确的解决方案。
更新:如Phil上面建议的那样,运行此命令也可以达到目的:
PHP应用程序/控制台原则:缓存:清除元数据
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 problemthen 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 !
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
这篇关于Symfony原则:模式:更新不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!