ef-migrations

How to manage Migrations in a project with multiple branches?

限于喜欢 提交于 2019-11-28 15:19:26
I have an ASP.NET MVC3 project that uses Entity Framework 4.3 with the code-first approach. I use Migrations to keep the database up-to-date. The project is under source-control and I have a number of branches. What I just realized is that there will be a problem when I want to merge one of my branches into the master. Since I have created migration-files in both branches, there will be overlapping migrations when I merge, which will probably cause conflicts. Is there a good way to manage Migrations in a project with multiple branches? Update One way would be to merge, then delete all

migration synch developmental and production databases

女生的网名这么多〃 提交于 2019-11-28 14:42:45
I am using MVC 5 with NET Framework 4.5.1. with Code-first. I am also using Migrations with the SQL 2012 server and (localdb)\v11.0. I am in the middle of developing a project using C# and MVC5. During development, I created a lot of new tables in my developmental computer and changed a the "Name" field which I believe the system makes an index for. I added it and deleted it several times. After that, I added a lot iof new unrelated tables, but for some reason, my migrations started giving me foreign constraint errors due to the indexes for the "Name" field. These errors kept multiplying as I

How to uninstall EF Core tables? Or how to remove all migrations ? Or how to call `dotnet ef database update 0` from user code?

南笙酒味 提交于 2019-11-28 14:30:26
I'm developing web app and near it small command line application that install ef core tables in the DB. Last can be done calling dbContext.Database.Migrate(); and this works. Now I want to provide unistall option (with this app). But how to remove migrations (means call functionality of dotnet ef database update 0 from my code) ? It could be not one command call (as it was in case with dbContext.Database.Migrate(); ). But snippet with loop through all migrations in migrations assembly and call of 'Downs'. EF Core provides publicly only the dbContext.Database.Migrate(); extension method used

Cant remove identity attribute from PK

帅比萌擦擦* 提交于 2019-11-28 14:12:21
I need to change the data type of the primary key on one of my tables to string from int (I didn't say I WANT to...). The migration generates this bit of code: AlterColumn("dbo.Venues", "ID", c => c.String(nullable: false, maxLength: 128)); This causes SQL server to complain that the data type must be int, bigint, etc because the column is an identity column. I added the following but it appears to have no effect: AlterColumn("dbo.Venues", "ID", c => c.Int(identity:false)); Question: How do I get the migration to change the data type from int to string? The following may be related to my

Entity Framework - Start Over - Undo/Rollback All Migrations

谁说我不能喝 提交于 2019-11-28 13:16:25
问题 For some reason, my migrations appear to have been jumbled/corrupted/whatever. I'm at the point where I just want to start over, so is there a way to completely undo all migrations, erase the history, and delete the migration code, so I'm back to square one? e.g.) PM> Disable-Migrations or Rollback-Migrations I don't want to "update" to an original migration step (i.e. something like an InitialSchema target) because I can't find it anymore. 回答1: You can rollback to any migration by using:

How to use migration programmatically in EntityFramework Codefirst?

﹥>﹥吖頭↗ 提交于 2019-11-28 10:55:01
I'm working in a project that uses EF Code First. I'm trying to use migration features. I don't want to use Package Console Manager. How can I execute the "Add-Migration" and "Update-Database" programmatically? add-migration TestMigration01 -force update-database You have a couple of choices. You can use the dbmigrator class from within your code: http://romiller.com/2012/02/09/running-scripting-migrations-from-code/ Or you can use migrate.exe which is handy for running them in a build step, etc. https://msdn.microsoft.com/en-us/data/jj618307.aspx 来源: https://stackoverflow.com/questions

Enable-Migrations installation error

眉间皱痕 提交于 2019-11-28 10:49:46
I'm running into a problem when enabling migrations on one of my projects. I execute Enable-Migrations command from the Nuget Console and receive an error saying: Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.TeamArchitect.ModelingProject.ModelProjectAutomationObject' in assembly 'Microsoft.VisualStudio.TeamArchitect.ModelingProject, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable." At D:\Solution\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:391 char:5 + $domain.SetData('startUpProject',

Code first custom SQL migration timeout exception

ぃ、小莉子 提交于 2019-11-28 10:46:15
I am trying to create FULL TEXT index using Entity Framework Migration by executing custom Sql. My migration class looks like this: public partial class DocumentContentFullTextIndex : DbMigration { public override void Up() { AlterColumn("dbo.Attachments", "ContentType", c => c.String(maxLength: 260)); Sql("CREATE FULLTEXT CATALOG FullTextIndexes AS DEFAULT;", true); Sql(@"CREATE FULLTEXT INDEX ON [Attachments]( Content TYPE COLUMN ContentType Language 'ENGLISH' ) KEY INDEX [PK_dbo.Attachments] ON FullTextIndexes;", true); } public override void Down() { AlterColumn("dbo.Attachments",

Foreign Key To Microsoft.AspNet.Identity.EntityFramework.IdentityUser?

僤鯓⒐⒋嵵緔 提交于 2019-11-28 10:10:43
I'm in VS 2013 and have just created an MVC application. I'm creating an object I intend to have a foreign key to the AspNetUsers table in the resulting database. The project does have an ApplicationUser (deriving from IdentityUser) that looks like a property-column match with the AspNetUsers table. How do we properly declare a foreign key to this? public MyObject { public string UserId { get; set; } [ForeignKey("UserId")] public ApplicationUser User { get; set;} // other properties } Now, I modify ApplicationUser to have a collection of MyObjects: public ApplicationUser : IdentityUser {

EF 5, Code First - Create a new database and run all migrations programatically

烂漫一生 提交于 2019-11-28 08:36:54
I'm using Entity Framework Code First migrations, and I have a scenario where I want to run a suite of integration tests. Each time the tests run, I want to re-create the database, and apply all migrations The steps should be: Drop the existing test database (if any) Create a new test database, and apply all migrations Seed data This is an existing project that I've added migrations to, and I used the Enable-Migrations command to create an "InitialCreate" migration that contains code to add all the tables to my database. The code in my custom IDatabaseInitializer is as follows: public void