Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add new enum column during migration

Can anyone please tell me how can I add a new column of type enum to my schema in order to implement a Doctrine Migration?

like image 337
Rui Gonçalves Avatar asked Jan 18 '10 11:01

Rui Gonçalves


People also ask

How do I add a column to an existing migration without losing data?

Make sure that when you are adding new column in your table, that column should be nullable, and should not be unique. Otherwise you will face error. Because when a new column is created it will be empty(not unique). In that condition you have to rollback the migration.

How do you insert an enum?

To insert data into an ENUM column, you use the enumeration values in the predefined list. For example, the following statement inserts a new row into the tickets table. In this example, instead of using the Low enumeration value, we used value 1. Since Low is mapped to 1, it is acceptable.


1 Answers

  1. modify your schema

  2. run ./symfony doc:generate-migrations-diff

    this will generate one or more files in lib/migrations/doctrine/

  3. run ./symfony doc:migrate

    this will apply the generated migrations to the database

  4. run ./symfony doc:build --all-classes

    this works for symfony >= 1.3/1.4 and will rebuild all form/filters/model classes according to the modified schema

remember that the migration is generated comparing the new schema.yml to the current model classes, so if you rebuild your classes before running generate-migrations-diff you're screwed.

like image 182
gpilotino Avatar answered Sep 19 '22 13:09

gpilotino