What is the difference between
symfony doctrine:generate-migrations-db
and
symfony doctrine:generate-migrations-models
I can’t notice any difference: I’ve tried with tables IN DB, NO schema.yml and NO models, both of them have no effect. No migrations generated.
I’ve tried with tables IN DB, GENERATED schema.yml and NO models, both of them have no effect. No migrations generated.
And lastly I’ve tried with tables IN DB, GENERATED schema.yml and GENERATED models, now both of them generate the same migrations classes :|.
Can’t really understand the difference. Or at least, what is the best way to start using migrations considering all scenarious: having models, but no DB and having DB, but no models.
Thanks.
Given an existing database with 1+ tables, running
will result in migration files being created for each table. Similarly, given a directory like
/lib/model/doctrinefilled with pre-existing model classes, runningwill result in migraiton files being created for each model.
With tables in the database, with or without schema.yml contents, and no models in
lib/model/doctrine, you just need to ensure you’re database.yml file has credentials to correctly connect to your database.Once you figure out the problem with your migrations files not generating, what I would do is something like to get started with migrations.
./symfony doctrine:build-schemaconfig/databases.ymlto point to a new blank database./symfony doctrine:generate-migrations-diff. This will create migrations based on your schema file to bring your (blank) database up to date./symfony doctrine:migrateand watch for errors. Fix them by fixing your schema file. Delete the migrations created in Step 4. Flush your databse./symfony doctrine:drop-db && ./symofny doctrine:build-dband go back to Step 4. Continue until you’re schema generates a clean set of migrations files that can run without error../symfony doctrine:build --model --forms --filtersNow you have a clean
schema.ymlfile, clean migrations that can bring a blank database up to date, and models that directly relate to yourschema.ymlfile and database.When you want to make a new change to your database, it’s now as simple as
schema.yml./symfony doctrine:generate-migrations-diff./symfony doctrine:migrateto make sure the migrations run without error./symfony doctrine:build --model --forms --filtersGoing through this process can be frustrating at times, but it’s something you only have to do once to create a really good based to build upon.