ef-migrations

Consolidating EF migrations into new InitialCreate

南楼画角 提交于 2019-12-02 17:51:34
I have been using EF migrations for some time now and have more than 100 migration files in my project. I would like to consolidate these into a single migration before moving forward - ie I want to replace the existing InitialCreate migration with a new version that takes all my subsequent changes into account so I can then delete all the other migration files. I do this very easily if I am not concerned with losing all the data in the DB, but I am. How can I achieve this whilst keeping all data intact and also retaining the ability to recreate the database from scratch (without data) by just

ASP.NET MVC 4, Migrations - How to run 'update-database' on a production server

女生的网名这么多〃 提交于 2019-12-02 17:41:18
I can use package manager to run 'update-database -verbose' locally. Probably a stupid question but I can't find it online - once my website is deployed - how can I run this manually on the server? Secondarily - what other strategies would you recommend for deploying database migrations to production - and how would they be preferable? Thanks amhed You have a couple of options: You could use update-database -script to generate the SQL commands to update the database on the server You could use the migrate.exe executable file that resides in the package folder on /packages/EntityFramework5.0.0

update the database from package manager console in code first environment

两盒软妹~` 提交于 2019-12-02 17:34:10
Code First Environment I'm trying to update the database from package Manager console.If my Domain class change, I have to drop and create the database,Instead of dropping the Database how can i update the database. I have already try by reading some blogs in google. commands PM> Install-Package EntityFramework By using this command i install the Entity Framework successfully. PM> Enable-Migrations By using this command it created the Migration file in my project. PM> Update-Database By using this command , i may update the table but i have a Problem here . Error Specify the '-Verbose' flag to

Is it possible to change the location of the EF Migrations “Migrations” folder?

删除回忆录丶 提交于 2019-12-02 17:01:18
By default, the add-migration command attempts to create the migration .cs file in Project Root Migrations I'd like to store my migrations along with the rest of my EF-related code in the \Data folder of my project: Project Root Data Migrations With this structure, when I execute PM> add-migration Migration1 in the NuGet console I receive the following error: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\MyProjectRoot\Migrations\201112171635110_Migration1.cs'. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init

Run EF migration on VSTS release

北城余情 提交于 2019-12-02 12:07:18
问题 When I release my Asp.Net MVC app to azure web app using VSTS and a Hosted VS2017 agent, the EF Migration (to Azure SQL) doesn't execute on application start the same way it can be done publishing from Visual Studio with the option "Execute Code First Migrations (Runs on application start)". What would be the specific steps on VSTS to make EF migration run and update the database the same way as when publishing from VS ? 回答1: Is possible to have VSTS use the same Publish Profile as in VS

Foreign key constraint, EF with collection of childobjects

自闭症网瘾萝莉.ら 提交于 2019-12-02 08:53:52
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 The relationship could not be changed because one or more of the foreign-key properties is non-nullable

Code First migration when entities have cross references with foreign keys

余生颓废 提交于 2019-12-02 05:41:01
问题 I have models that have references to each other: public class Dept { [Key] public int DeptId { get; set; } [ForeignKey("ManagerId")] public Emp Manager { get; set; } public int? ManagerId { get; set; } public string DeptName { get; set; } } public class Emp { [Key] public int EmpId { get; set; } [Required] [ForeignKey("DeptId")] public Dept Dept { get; set; } public int DeptId { get; set; } public string Name { get; set; } } When I call Add-Migration, I get error: The ForeignKeyAttribute on

Can't add Entity Framework Core migrations to .NET Standard 2.0 project

放肆的年华 提交于 2019-12-02 03:59:48
I've got a Solution with many projects. One of them ( Domain ) is a .NET Standard 2.0 project where I made my EF Core DbContext implementation for which I want to enable database migrations . I saw various blogs and Q/A forums where the problem was explained but none of the proposed solutions seem to work for me because of the .NET Core newer version or (probably) for my particular solution configuration. Solution projects Engine (.NET Core 2.1 Console App) Web API (.NET Core 2.1 Library) Application (.NET Core 2.1 Library) Domain (.NET Standard 2.0 Library) WindowsService (.NET Core 2.1

Entity Framework Code First Migrations thinks there is a change that shouldn't be there

眉间皱痕 提交于 2019-12-02 00:37:23
问题 I have a website and a windows service that both reference the same project to get an Entity Framework data context. Each time I start the windows service, Entity Framework runs an automatic migration that changes one of the database columns from NOT NULL to NULL (no other changes are made). The property for that column is marked as [Required], and the website (which points to the exact same version of the exact same DLL for its model), properly thinks that the database should be NOT NULL for

Entity Framework Code First Migrations thinks there is a change that shouldn't be there

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 20:55:18
I have a website and a windows service that both reference the same project to get an Entity Framework data context. Each time I start the windows service, Entity Framework runs an automatic migration that changes one of the database columns from NOT NULL to NULL (no other changes are made). The property for that column is marked as [Required], and the website (which points to the exact same version of the exact same DLL for its model), properly thinks that the database should be NOT NULL for that column. I tried disabling automatic migrations and, as expected, the service then crashed because