简体   繁体   中英

Symfony2: Database schema and entities not updating with changed metadata

I am having trouble updating the schema in Symfony2.

I have imported a database into Symfony2 using doctrine and that created all the ORM files in YML.

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.

The import created the orm.yml files in /src/{name}/{my}bundle/Resources/config/doctrine/metadata/orm/{table}.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.

The file 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.

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 .

Therefor all Entities in this new Bundle got never exported with php app/console doctrine:schema:update --dump-sql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM