How to add a column in entity on Symfony 1.4 using

2019-07-29 06:25发布

I have some problem. I work on symfony 1.4. I want to add a new column in my table and generate in php getter and setter to use it.

So In my shema.yml I add my column in my table like this:

version : {type: integer}
userName_canonical : {type: varchar(255)}
email_canonical : {type: varchar(255)}
qualifications: {type: array}
qualification_autre: {type: string}
promo: {type: boolean, default: 0}
next_request_at: {type: date, default: null}<-----

But I search everywhere and I don't know how I can modify my entity and create this column in my database. Someone know which is the command using to modify my entity in symfony 1.4 ??

Thank in advance

2条回答
劳资没心,怎么记你
2楼-- · 2019-07-29 07:07

According to the Symfony 1.4 documentation you need to run these commands after modifying your schema file:

php symfony doctrine:build --model

php symfony doctrine:build --sql

php symfony doctrine:insert-sql

Before running these commands, please read to this documentation page under the heading 'The ORM' just to make sure those commands are what you're looking for.

Doctrine entities can then be generated via this command

php symfony doctrine:build --model

Make sure to backup any existing work before doing this however, as it may overwrite any changes to existing classes.

查看更多
叛逆
3楼-- · 2019-07-29 07:18

Before you create the new model classes (using the doctrine:build commands), you should create migration files.

For me, the process is usually:

  • ./symfony doctrine:generate-migrations-diff

    This should create a new file in lib/migrations/doctrine with commands to add any new columns.

  • ./symfony doctrine:build --all-classes

    This will create or update the classes in lib/{model,form,filter}/doctrine/base to include the new columns.

  • ./symfony doctrine:migrate

    This actually runs the migration. Otherwise you'll get a SQL error because of the missing column. The migration clearly needs to be run on production as well; we have that as part of our deploy scripts to run every time.

If you've already built new classes, you'll need to add a few steps to the beginning of the above process:

  • Temporarily comment out or revert the schema.yml change
  • Run ./symfony doctrine:build --all-classes
  • Make the schema.yml change again
  • Go back to step 1, the generate-migrations-diff step above.
查看更多
登录 后发表回答