10

I've searched pretty much everywhere but I wasn't able to find anything.

Is there a command or a procedure to change the name of a table (so inside doctrine annotation) without loosing data?

Basically, something that will produce something like

RENAME TABLE old_table TO new_table;

or

ALTER TABLE old_table RENAME new_table;

MySQL commands taken from here

Should I write manually the migration file with doctrine:migrations:generate?

Muc
  • 1,464
  • 2
  • 13
  • 31
DonCallisto
  • 29,419
  • 9
  • 72
  • 100

1 Answers1

19
  1. Change table name for given entity.

    /** @Entity @Table(name="new_table_name") */
    class MyEntity { ... }
    
  2. Generate a new migration.

  3. Erase contents of up() and down() methods and replace them with custom SQL (ALTER TABLE ... RENAME TO ...).

Keep in mind that migration generator is meant as utility/semi-automatic tool.

Jason Roman
  • 8,146
  • 10
  • 35
  • 40
Crozin
  • 43,890
  • 13
  • 88
  • 135
  • 2
    Yes, so, basically, I can reach the same by running `php app/console doctrine:migrations:generate` (that, indeed, is what I've done 'till now) – DonCallisto Dec 30 '15 at 16:18
  • 12
    This doesn't handle updating foreign key constraints. – fubar May 04 '18 at 03:13