I'm playing around with Entity framework and continuous builds. So far i'm able to run a migration or series of migrations without any problem by using migrate.exe and the appropriate arguments.
However, i've hit trouble when trying to get migrate.exe to kick out a script, rather than perform the migration, in the same way as I could get by running
update-database -TargetMigration TestMigration -script
from within Package Manager Console in Visual Studio.
Is there currently a way to do this?
Thanks.
With From and To The following generates a SQL script from the specified from migration to the specified to migration. You can use a from that is newer than the to in order to generate a rollback script.
Migrations are enabled by default in EF Core. They are managed by executing commands. If you have Visual Studio, you can use the Package Manager Console (PMC) to manage migrations. Alternatively, you can use a command line tool to execute Entity Framework CLI commands to create a migration.
Since the 10/22/2017 you can do it thanks to this PR: https://github.com/aspnet/EntityFramework6/commit/02ec6b8c9279f93f80eeed1234e5ce0acfce5f31
Here the Entity Framework 6.2 release notes that implements this functionality (see 'Migrate.exe should support -script option' section): https://blogs.msdn.microsoft.com/dotnet/2017/10/26/entity-framework-6-2-runtime-released/
Follow those steps:
migrate.exe yourMigrationAssembly.dll /startupConfigurationFile=”..\web.config” /scriptFile="migrationOutput.sql"
It will generate the the file "migrationOutput.sql" that contains the SQL you have to execute on your target environment DB based on the migrations that are not yet applied on it.
It is currently not supported. Please add your vote to the issue: Migrations: -Script for Migrate.exe
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With