[英]Symfony2: Database schema and entities not updating with changed metadata
I am having trouble updating the schema in Symfony2. 我无法在Symfony2中更新架构。
I have imported a database into Symfony2 using doctrine and that created all the ORM files in YML. 我已经使用理论将数据库导入到Symfony2中,并在YML中创建了所有ORM文件。
I have created all the entities from this metadata and it worked great, but if I want to change the database schema using the orm.yml files, It does not update my database or even update the entities when I regenerate them. 我已经从该元数据创建了所有实体,并且效果很好,但是如果我想使用orm.yml文件更改数据库架构,那么在重新生成实体时它不会更新数据库,甚至不会更新实体。
The import created the orm.yml files in /src/{name}/{my}bundle/Resources/config/doctrine/metadata/orm/{table}.orm.yml 导入在/src/{name}/{my}bundle/Resources/config/doctrine/metadata/orm/{table}.orm.yml中创建了orm.yml文件。
It was created with no errors. 它创建没有错误。
When I do: 当我做:
php app/console doctrine:schema:update --dump-sql
it displays: 它显示:
ALTER TABLE accounttypes CHANGE description description VARCHAR(45) NOT NULL
So I: 所以我:
php app/console doctrine:schema:update --force
And: 和:
Updating database schema...
Database schema updated successfully! "1" queries were executed
I can do this over and over again and the same query appears and I execute it and it tells me it is done, but again it shows that it needs to be done again. 我可以一遍又一遍地执行此操作,并出现相同的查询,然后执行它,并告诉我已完成,但再次表明需要再次执行。
I then have gone to the orm.yml files and changed them drastically, but nothing no new queries appear other than the one that is always there when I do this. 然后,我进入了orm.yml文件并进行了大幅度的更改,但是除了执行此操作时始终存在的查询之外,没有其他任何查询出现。
The file AccountTypes.orm.yml 文件AccountTypes.orm.yml
Accounttypes:
type: entity
table: accounttypes
fields:
description:
id: true
type: string
length: 45
fixed: false
nullable: false
generator:
strategy: IDENTITY
lifecycleCallbacks: { }
Change to this: 更改为此:
Accounttypes:
type: entity
table: accounttypes
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
description:
id: true
type: string
length: 50
lifecycleCallbacks: { }
And it still tells me I need to: 它仍然告诉我我需要:
ALTER TABLE accounttypes CHANGE description description VARCHAR(45) NOT NULL
I have also tried using DoctrineMigrationsBundle and the same query shows up needing done. 我也尝试过使用DoctrineMigrationsBundle,并且相同的查询显示需要完成。 I migrate;
我迁移; It says the query is done and when I use it again the same query shows up.
它说查询已完成,当我再次使用它时,将显示相同的查询。
Does anybody have any idea how this is happening? 有人知道这是怎么回事吗? I am stuck on this, so any help is greatly appreciated.
我对此感到困惑,因此不胜感激。
按照上面的@Tomasz ,确保您的Symfony2不会尝试使用批注而不是yaml来设置数据库。
I had the same problem. 我有同样的问题。
Reason was - a newly created bundle was not yet added to app\\config.yml
. 原因是-新创建的捆绑包尚未添加到
app\\config.yml
。
Therefor all Entities in this new Bundle got never exported with php app/console doctrine:schema:update --dump-sql
因此,这个新捆绑包中的所有实体从未与
php app/console doctrine:schema:update --dump-sql
一起导出php app/console doctrine:schema:update --dump-sql
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.