1

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

3
  • Just out of curiosity more than anything else, how come you're on Symfony 1.4? Is this a legacy project? Commented Jan 3, 2018 at 13:37
  • Yes It's a legacy project. And it's very difficult to me because I always use Symfony2. Commented Jan 3, 2018 at 13:43
  • Which ORM are you using - Propel or Doctrine? Commented Jan 4, 2018 at 17:44

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Yes I modify my schema.yml and I want to modify my php class and create this column in my database in consequence. But I have a question. With this command there will be only the php class which are modify and my column will be created on my table in database ? Anything else ?
It's just I hope this command don't delete the data in my table and they don't create a file in double.
@arendelle I'd missed something there, my original answer only included ways to generate the sql structure. Apparently running this command php symfony doctrine:build --model will generate a php class in 'lib/model/' for you. If we're talking about existing classes, you are probably better off doing this manually or running that command ONLY after backing up your existing work.
Thank you for your help! But after I use this command: "php symfony doctrine:build --model" i try to access my application and I got this error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'i.label' in 'field list'
@arendelle it looks like somewhere the schema doesn't match up with the required SQL and classes. It's going to be a pain you'll have to manually comb through to find out where there was a mismatch. Or, you could revert back to where you started and manually add the columns into the db and the php classes.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.