How to add a column in entity on Symfony 1.4 using line command?

自作多情 提交于 2019-12-11 05:04:03

问题


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


回答1:


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.




回答2:


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.


来源:https://stackoverflow.com/questions/48078514/how-to-add-a-column-in-entity-on-symfony-1-4-using-line-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!