![]() ![]() In the Package Manager Console this is done as follows: Remove a migration that was already applied in the database: To remove a migration that has already been applied in the database, we must use the Force option. In the Package Manager Console this would be: So, if we want to remove the penultimate migration, we should run the commands to remove migrations twice. Removing the penultimate migration: Although we can not specify the migration that we want to eliminate, we can execute the Remove-Migration command several consecutive times, which, in effect, allows us to delete the migration we want, but one at a time. Note: If you have more than one Data Context, it is mandatory that you specify in the previous command the name of the Data Context to be used. In the dotnet CLI, the equivalent command would be the following: In the Package Manager Console we can do this in the following way: This removes the last migration, as long as it has not been previously applied in the database. Examples:īasic use: The basic use would be to simply execute the command without passing any option. ![]() This command also has the basic options such as Context and Project to indicate the Data Context and the project to use, respectively. By default, if you try to remove a migration which has already been applied to the database, an error is thrown at us, the only way we can avoid this error is using the Force option. Force: Reverts a migration even if it has been applied to the database.These are some of the options of Remove-Migration: In the dotnet CLI, this command is found in: Sometimes this could cause data loss, so it is important to proceed with caution. For example: If in a migration you added a column in a table, then when you remove that migration you will also want to remove that column. ![]() If the migration has already been applied to the database, then removing a migration involves touching that database to revert the changes that were made to it. If the migration has not been applied to the database, in essence, there is no consideration to have, the command will be applied as you expect, that is, it will simply remove the files from the migrations that you indicate you want to delete. An important consideration is whether the migration has already been applied or not in the database. It is useful in situations where you have created one or several migrations, and you discover that you have made an error, and you want to undo those migrations. We continue the theme of the Entity Framework commands! Commands that we have already seen:Īs the name implies, this command is used to remove a migration, specifically the most recent one. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |