php Symfony2:数据库架构和实体不会随着元数据的变化而更新

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10659087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 22:44:22  来源:igfitidea点击:

Symfony2: Database schema and entities not updating with changed metadata

phpsymfonydoctrinedoctrine-ormyaml

提问by Apothan

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. I migrate; It says the query is done and when I use it again the same query shows up.

我也尝试过使用 DoctrineMigrationsBundle,同样的查询显示需要完成。我迁移;它说查询已完成,当我再次使用它时,会出现相同的查询。

Does anybody have any idea how this is happening? I am stuck on this, so any help is greatly appreciated.

有人知道这是怎么回事吗?我坚持这一点,所以非常感谢任何帮助。

回答by Meetai.com

As per @Tomasz, above, make sure that your Symfony2 doesn't try to use annotations to setup database instead of yaml.

根据上面的@Tomasz,请确保您的 Symfony2 不会尝试使用注释来设置数据库而不是 yaml。

回答by dufte

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