locked
A quick migrations question, is automatic migrations the same as..? RRS feed

  • Question

  • User1034446946 posted

    Hi

    I am starting to go live with a project so I need to get serious with migrations, I have always wagged it till now.

    I have always thought that automatic migrations was the same as adding a migration and applying it, now I am thinking this is incorrect.

    If the following right or can someone please explain it.

    Automatic migrations, is when you don't add a migration and the EF does all the work without any additional help, and a manual migration is when you add a migration, sometimes change the code and then apply the migration.

    Also if I use the add-migration, can i just delete it, if I no longer want it?

    Any information would be appreciated.

    Tuesday, June 16, 2015 6:39 AM

Answers

  • User-821857111 posted

    Automatic migrations, is when you don't add a migration and the EF does all the work without any additional help, and a manual migration is when you add a migration, sometimes change the code and then apply the migration.
    Yes.

    Also if I use the add-migration, can i just delete it, if I no longer want it?
    Yes - so long as you haven't run the update-database command. I do this quite often - when I add a new migration, read the migration code and realise I need to make other changes to the model before applying the migration. I simply delete the migration code file and run add-migration again. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 16, 2015 8:31 AM

All replies

  • User-821857111 posted

    Automatic migrations, is when you don't add a migration and the EF does all the work without any additional help, and a manual migration is when you add a migration, sometimes change the code and then apply the migration.
    Yes.

    Also if I use the add-migration, can i just delete it, if I no longer want it?
    Yes - so long as you haven't run the update-database command. I do this quite often - when I add a new migration, read the migration code and realise I need to make other changes to the model before applying the migration. I simply delete the migration code file and run add-migration again. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 16, 2015 8:31 AM
  • User1034446946 posted

    thanks

    and if I set allowautomaticmigrations to false, when I run update-database, do I always have to add the migration name to ensure I do the migration?

    Tuesday, June 16, 2015 8:51 AM
  • User-821857111 posted

    No. The update-database command will run the newest migration. If you have multiple  migrations that have't been committed, you will get an error requiring you to specify the name of the the oldest migration that hasn't been run. If you always run update-database after you have created a new migration, you don't to specify the migration name.

    Tuesday, June 16, 2015 4:43 PM
  • User1034446946 posted

    Thanks for the help.

    Tuesday, June 16, 2015 6:13 PM