How to manage Migrations in a project with multiple branches?

There is a much better solution for handling entity framework migration merge conflicts on a similar question. All you need to do after a merge is to re-scaffold the meta data of the migration in the target branch. That is you do not rescaffold the up/down code, just the state in the resx-file. add-migration [the_migration_to_rescaffold_metadata_for] … Read more

Enable Migrations with Context in Separate Assembly?

This will only work in EF 6, but there was a release that added the -ContextProjectName parameter to the -enable-migrations command. By using this command you could do the following: enable-migrations -ContextProjectName MyProject.MVC -StartUpProjectName MyProject.MVC -ContextTypeName MyProject.MVC.MyContextFolder.MyContextName -ProjectName MyProject This will add migrations to your MyProject project using the context in the MyProject.MVC. You need … Read more

Change data in migration Up method – Entity Framework

In the middle of a migration, it’s better to use Sql() method to update database data. Sql(“UPDATE dbo.RequestValidationErrors SET IsBreaking = 0 WHERE WordCode=”RequestValidationError.MoreThanOneItemFound””); Also you should define the default value for the new column. So the solution should be something like this: public override void Up() { AddColumn(“dbo.RequestValidationErrors”, “IsBreaking”, c => c.Boolean(nullable: false, default: … Read more

Using Entity Framework (code first) migrations in production

There is a Database Initializer you can use to achieve the migration to latest version on startup (or better, the dbinitializer will kick in on first db access), the MigrateDatabaseToLatestVersion, you use it like that: Database.SetInitializer<ObjectContext>( new MigrateDatabaseToLatestVersion<ObjectContext, Configuration>()); Regarding having one file per migration, if you enable automatic migrations you will find them in … Read more

Code-first migration: How to set default value for new property?

If you see the generated migration code you will see AddColumn AddColumn(“dbo.report”, “newProperty”, c => c.String(nullable: false)); You can add defaultValue AddColumn(“dbo.report”, “newProperty”, c => c.String(nullable: false, defaultValue: “old”)); Or add defaultValueSql AddColumn(“dbo.report”, “newProperty”, c => c.String(nullable: false, defaultValueSql: “GETDATE()”));

How to explicitly name the database when using Entity Framework Migrations 4.3

You can avoid managing it in app.config by offering it as a parameter: Update-Database -Verbose -ConnectionString “CONNECTIONSTRING” -ConnectionProviderName “System.Data.SqlClient” -StartupProjectName WEBSITE_PROJECT -ProjectName MIGRATION_PROJECT Easy-piezy, if you love to type endlessly.

Entity Framework code-first: migration fails with update-database, forces unneccessary(?) add-migration

I also tried deleting the database again, called update-database and then add-migration. I ended up with an additional migration that seems not to change anything (see below) Based on above details, I think you have done last thing first. If you run Update database before Add-migration, it won’t update the database with your migration schemas. … Read more

EF 5 Enable-Migrations : No context type was found in the assembly

I am surprised that no one mentioned the obvious answer to this question: Entity Framework requires a context before enable-migrations will work. The error message the OP posted suggests that no context was found. Sure, it could be because the package manager console doesn’t “see” the context–in which case the accepted answer is a possible … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)