ef-migrations

Make EF4.3 Code First Migrations ignore pending migrations

北战南征 提交于 2019-12-04 07:18:00
I have a local instance of a database that I recently created using DbContext.Database.Create() , so the __MigrationHistory table exists with an InitalCreate entry that matches the code at the moment. Some code-based migrations exist in the Migrations folder, however. These will be run in our development and staging environments to bring those databases in line with the code. I don't need to apply them locally, however, since I created the database using the current code. I now need to make a change to the model and create the corresponding migration. But when I run Add-Migration TestMigration

Error while running Update-Database

北城余情 提交于 2019-12-04 07:08:14
I got the following error while running Update-Database -Verbose : Using StartUp project 'WebApplication'. Using NuGet project 'WebApplication'. Specify the '-Verbose' flag to view the SQL statements being applied to the target database. Target database is: 'Frappuccino' (DataSource: (Localdb)\v11.0, Provider: System.Data.SqlClient, Origin: Configuration). No pending explicit migrations. Applying automatic migration: 201402032027563_AutomaticMigration. ALTER TABLE [dbo].[Clients] ALTER COLUMN [ID] [int] NOT NULL System.Data.SqlClient.SqlException (0x80131904): The object 'PK_dbo.Clients' is

Foreign key constraint, EF with collection of childobjects

帅比萌擦擦* 提交于 2019-12-04 06:10:30
问题 I'm trying to update a model, but get the error "The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted." From what I understand from

SQL Server CE Code First migrations problems

守給你的承諾、 提交于 2019-12-04 04:51:41
I have a bunch of problems trying to enable (code-first) migrations for my SQL Server Compact 4.0 database for my desktop .NET app. Enable-Migrations does work and the directory Migrations is created. After that when I try to run Add-Migration InitialMigration , I get: Access to the database file is not allowed. [ 1914,File name = Logo.sdf,SeCreateFile ] This is the first problem, but I solved it by running Visual Studio as Administrator... don't like that solution and also don't know if later in production it will work without the app being run in Admin mode. I let that problem aside for now.

DbMigrator - verbose code-first migration

三世轮回 提交于 2019-12-04 04:42:57
When using Package Manager Console, you can run the following command: PM> Update-Database -Verbose The -Verbose switch will write all attempted SQL commands to the console window, which is quite useful for debugging. You can use the DbMigrator class to do the same in code: Configuration config = new Configuration(); //... (set up the config object) DbMigrator migrator = new DbMigrator(config); migrator.Update(); Is there something like the -Verbose switch if you use the DbMigrator class? I looked all over the documentation, but couldn't find anything. See if this article solves your problem:

EF Core Migrations with Multiple DB Schemas

牧云@^-^@ 提交于 2019-12-04 04:39:53
EF Core 1.1 and SQL Server 2016 We are running a microservice application with some microservices having independent few tables. One of the solutions to have many tables for individual microservice, is to give these services a unique schema (e.g. not DBO) and put all of them in one database (good for cost + maintenance). That works fine in EF 6, however, looking at the generated dbo.__EFMigrationsHistory in core, it looks like core doesn't take the schema into account. I am aware that the migration in EF Core has changed to look in the code rather than the DB, but my problem is the version

Entity Framework - Seed AddOrUpdate with multi column index as identifier

拈花ヽ惹草 提交于 2019-12-04 03:04:32
I am trying to seed a database using the context.AddOrUpdate method, but the problem is that I need to make the inserted data unique based on a multi column index. [Table("climbing_grades")] public class ClimbingGrade : EntityBase { /// <summary> /// The name of the climbing grade, e.g.: 7a, VII, etc. /// </summary> [Index("IX_Name_GradeType", 1, IsUnique = true)] public string Name { get; set; } /// <summary> /// Tries to display the average difficulty of the described grade. /// Matching the different grades can be difficult because its always /// a subjective rating and there exists no norm

Entity Framework Code First Data Migrations not working with VS2012 Web Deploy

匆匆过客 提交于 2019-12-04 03:02:40
I have created an MVC 3.0 application using Visual Studio 2012, .NET 4.5 and Entity Framework 5.0. Using Code First Data Migrations, I am able to correctly propagate model changes to my local test database, but I can't figure out how to get this to work when deploying to my staging and production servers using Web Deploy. I have read the following article ... http://msdn.microsoft.com/en-us/library/dd394698(v=vs.110)#dbdacfx ... which explains what's supposed to happen, but it's not working for me, as Web Deploy seems unable to detect that I am using Entity Framework. The tutorial shows a

Entity framework manually deleted tables cant be generated from EF migration

混江龙づ霸主 提交于 2019-12-04 02:44:13
I have created migration and created the database and the tables . For example the tables are A B C D E . Now again I have changed some part of code and ran update-database command . Everything went smooth and nice and the tables showed the columns . Now accidentally I manually deleted one two tables D and E . Now when I try to run the migration with update-database . It runs properly but doesn't create the tables which I deleted manually . I tried to delete the existing migration and re-run update-database . It gives the error that apart from the two tables . There already an object existing

Merging migration entries in Entity Framework

。_饼干妹妹 提交于 2019-12-04 02:20:15
I have an Entity Framework 6 CF project that has a few migrations already in place. The model is now stable and there is no need to keep the migration history that already exists. Is there a way to reset the model and merge all migration commands into the initial migration? As an example, the first migration adds a column while the second migration adds a unique, non-clustered index. I now want to see all these changes directly in OnModelCreating rather than in separate migrations. Migrations have both an Up and Down . You can always Re-Scaffold your application by tearing the migrations down