I have a code-first entity model in EF5. But I want to manage the database changes manually -- I do not want EF to modify my existing database and all its data. But when I make parallel changes in the EF mapping and in the database, EF refuses to operate properly telling me I need to use code first migration. How do I turn this off?
Delete your Migrations folder. Create a new migration and generate a SQL script for it. In your database, delete all rows from the migrations history table. Insert a single row into the migrations history, to record that the first migration has already been applied, since your tables are already there.
Hi @PanagiotisKanavos, as you mentioned, it does not require migration.
Delete the row corresponding to your migration that you want to unapply (Say "yes" to the warning, if prompted). Run "dotnet ef migrations remove" again in the command window in the directory that has the project. json file. Alternatively, run "Remove-Migration" command in the package manager console.
Code First Migrations is the recommended way to evolve your application's database schema if you are using the Code First workflow. Migrations provide a set of tools that allow: Create an initial database that works with your EF model. Generating migrations to keep track of changes you make to your EF model.
set the Database.SetInitializer to null.
public class DatabaseContext: DbContext { //the base accepts the name of the connection string provided in the web.config as a parameter public DatabaseContext() : base("DatabaseContext") { //disable initializer Database.SetInitializer<DatabaseContext>(null); }
So the most complete answer that I have found is this:
Migrations
folder inside your project. Database.SetInitializer<DatabaseContext>(null);
inside your DatabaseContext initializer. __MigrationHistory
inside your database. For EF6+ the table is located under Tables
but for earlier versions it is located under System Tables
.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