ef-migrations

Database First to Code First EF - Migrations Key and Constraint Names not matching DB

烈酒焚心 提交于 2020-01-14 14:23:57
问题 I recently updated my project from Database First to a Code First Model, using this method: Link Everything seemed to be working until I wanted to update my FK and PKs on an existing table. This was a 1-0, 1-1 relationship. So the PK of Company table was the FK and PK of the DriverScorecardSetting table. So this is the entity that the Tool generated for the DriverScorecardSetting table. [Table("DriverScorecardSetting")] public partial class DriverScorecardSetting { [Key] [DatabaseGenerated

Database First to Code First EF - Migrations Key and Constraint Names not matching DB

柔情痞子 提交于 2020-01-14 14:23:06
问题 I recently updated my project from Database First to a Code First Model, using this method: Link Everything seemed to be working until I wanted to update my FK and PKs on an existing table. This was a 1-0, 1-1 relationship. So the PK of Company table was the FK and PK of the DriverScorecardSetting table. So this is the entity that the Tool generated for the DriverScorecardSetting table. [Table("DriverScorecardSetting")] public partial class DriverScorecardSetting { [Key] [DatabaseGenerated

Migrate entity with updated DatabaseGeneratedOption in Entity-Framework

僤鯓⒐⒋嵵緔 提交于 2020-01-14 09:52:10
问题 I have created code-first app according to this article - Code First to a New Database. Now I am going to change DatabaseGeneratedOption for Blog.BlogId . I changed my code in next way: public class Blog { [Key] [DatabaseGenerated(DatabaseGeneratedOption.None)] public int BlogId { get;set; } ... } And created migration for this code update: public override void Up() { DropForeignKey("dbo.Posts", "BlogId", "dbo.Blogs"); DropPrimaryKey("dbo.Blogs"); AlterColumn("dbo.Blogs", "BlogId", c => c.Int

Migrate entity with updated DatabaseGeneratedOption in Entity-Framework

为君一笑 提交于 2020-01-14 09:52:08
问题 I have created code-first app according to this article - Code First to a New Database. Now I am going to change DatabaseGeneratedOption for Blog.BlogId . I changed my code in next way: public class Blog { [Key] [DatabaseGenerated(DatabaseGeneratedOption.None)] public int BlogId { get;set; } ... } And created migration for this code update: public override void Up() { DropForeignKey("dbo.Posts", "BlogId", "dbo.Blogs"); DropPrimaryKey("dbo.Blogs"); AlterColumn("dbo.Blogs", "BlogId", c => c.Int

Cannot insert the value NULL into column 'Discriminator' AspNetUsers Table

笑着哭i 提交于 2020-01-14 08:10:12
问题 After a code first migration, adding a user using the register fails with: Cannot insert the value NULL into column 'Discriminator', table 'aspnet-BSF2013-20130918101120.dbo.AspNetUsers'; column does not allow nulls. The create user code is the default code generated by the Project Template (Vs2013, MVC project with EF5) Before a successful migration, the Registration code worked, so I'm guessing that membership has been altered by EF. 来源: https://stackoverflow.com/questions/18938514/cannot

Cannot insert the value NULL into column 'Discriminator' AspNetUsers Table

房东的猫 提交于 2020-01-14 08:09:29
问题 After a code first migration, adding a user using the register fails with: Cannot insert the value NULL into column 'Discriminator', table 'aspnet-BSF2013-20130918101120.dbo.AspNetUsers'; column does not allow nulls. The create user code is the default code generated by the Project Template (Vs2013, MVC project with EF5) Before a successful migration, the Registration code worked, so I'm guessing that membership has been altered by EF. 来源: https://stackoverflow.com/questions/18938514/cannot

EF - Default value for new column with automatic migration

我的梦境 提交于 2020-01-14 08:03:46
问题 I use EF code first and automatic migrations. I want to add a new column to my model - a boolean column to present "active" (true) or "inactive" (false). How can I add this column and set a default value ("true") for the rows that already in the DB - with automatic migrations? 回答1: Tamar, you need set default value, see next sample: namespace MigrationsDemo.Migrations { using System; using System.Data.Entity.Migrations; public partial class AddPostClass : DbMigration { public override void Up

EF - Default value for new column with automatic migration

蹲街弑〆低调 提交于 2020-01-14 08:03:14
问题 I use EF code first and automatic migrations. I want to add a new column to my model - a boolean column to present "active" (true) or "inactive" (false). How can I add this column and set a default value ("true") for the rows that already in the DB - with automatic migrations? 回答1: Tamar, you need set default value, see next sample: namespace MigrationsDemo.Migrations { using System; using System.Data.Entity.Migrations; public partial class AddPostClass : DbMigration { public override void Up

Error while doing Migrations EF core 2.0, changing Identity id from string to int

十年热恋 提交于 2020-01-14 07:55:29
问题 Scenario: I have received auto generated project in ASP.NET CORE from my colleague. There is auto-generated code for Account/Manage service. This code includes ApplicationUser Class, DBContext and migration folder with 00000000000000_CreateIdentitySchema.cs and 20180323155805_Snapshot.cs. I have been trying to change my User class to have integer id. To do that I added generic to IdentityUser: public class ApplicationUser : IdentityUser**<int>** { } I also had to create ApplicationRole class,

Downgrade (Rollback) Database with code-first in production environment

让人想犯罪 __ 提交于 2020-01-13 08:04:23
问题 I have a web application that I install on my customers' computers for their inner use. I use C# MVC5 and code-first Entity Framework. I used automatic migration=true but I stopped and set it to false. I installed it on a production environment (release) - with a deploy-package (no Visual Studio). I have a customer with the application - version 1. Now I want to upgrade to version 2. I want to enable to upgrade the App's DB (in production file, with CMD installation from a package), but to