EF CodeFirst: Either the parameter @objname is ambiguous or the claimed @objtype (COLUMN) is wrong

If you’re using Code First and have (an) existing Migration script(s) and are trying to overwrite a change (i.e. renaming a column) that has since been deleted, then you’ll get that error output. Simplest way is to delete the migration script, Add-Migration via NuGet, and then update the database.

Confusion over EF Auto Migrations and seeding – seeding every program start

The fact that the Seed method ran only when the database changed was quite limiting for the database initializers that shipped in EF 4.1. It was limiting because sometimes you needed to update seed data without changing the database, but to make that happen you had to artificially make it seem like the database had … Read more

Automatic Migrations for ASP.NET SimpleMembershipProvider

update-database -verbose doesn’t work because your model has been changed after your data table already existed. First, make sure there are no changes to the UserProfile class. Then, run: Add-Migration InitialMigrations -IgnoreChanges This should generate a blank “InitialMigration” file. Now, add any desired changes to the UserProfile class. Once changes are added, run the update … Read more

Entity Framework – Migrations – Code First – Seeding per Migration

When I have fixed data that I want to insert with a migration, I put the inserts directly in the Up() migration using calls to Sql(“Insert …”). See the note halfway down this page: how to insert fixed data You prevent duplicates in the Seed method by calling the AddOrUpdate overload that takes an identifier … Read more

Code First Migration with Connection Strings

On the package manager console type: Get-Help Update-Database Relevant part: Update-Database [-SourceMigration <String>] [-TargetMigration <String>] [-Script] [-Force] [-ProjectName <String>] [-StartUpProjectName <String>] [-ConfigurationTypeName <String>] [-ConnectionStringName <String>] [<Com monParameters>] So you can do a Update-Database -ConnectionStringName “MyConnectionString” and it should work like a charm. You also have a MigrateDatabaseToLatestVersion database initializer, if you set it (via Database.SetInitializer()), … Read more

How to run Seed() method of Configuration class of migrations

Answering your first question. Create a Migration by running add-migration SeedOnly Clear out all Up() and Down() code generated if there was any pending changes public partial class SeedOnly : DbMigration { public override void Up() { } public override void Down() { } } Then you can Target a Specific Migration by running update-database … Read more