P
P
P7472021-10-24 16:31:25
symfony
P747, 2021-10-24 16:31:25

Features on migrations in Symfony?

Good afternoon!
Tell me, in Yii, for example, to add a column, a foreign key, an index, a table, etc., you need to create a new migration class and add it there through the constructor or pure sql code. The migration "turns" into a transaction, after a successful migration it is written to the migration table. Further, the model is manually or automatically updated (some analogue of the entity in Symfony).
I noticed that when creating a new migration, code is placed in it (for example, to create a table), which is already in the old migration. Maybe, of course, I misunderstood or configured something.
In general, if, for example, I need to add a column, an index to the table, or change the column type, etc., if I change it in essence, when calling Make bundle, will it all generate a new migration with the necessary code, for example, to add a column? Will the existing sql code be added, for example, to create a table that exists?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Flying, 2021-10-24
@P747

Symfony uses Doctrine by default, for which there is Doctrine Migrations .
Since Doctrine is a data mapper, you don't need to "add a column / index / change column type to the table", instead you need to change your entities and mappings for them (read more here ), and then create a migration for it using the command doctrine:migrations:difffor Symfony console. Because the command works on comparing database schemas - as a result, you will get a migration with SQL scripts to apply and rollback changes made to your mappings.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question