데이터베이스에 기존 테이블에 새 열을 추가하려고합니다. 클래스에 새 필드를 지정하고 Add-Migration 명령을 실행할 때마다 AddColumn 대신 CreateTable 메서드를 사용하여 전체 테이블에 대한 마이그레이션 클래스. 다음은 클래스 및 생성 된 마이그레이션 클래스 코드입니다. Add-Migration이 Entity Framework Core의 기존 테이블에 열을 추가하지 않음
public class UserSetup
{
public int Id { get; set; }
public string Name { get; set; }
public bool Age{ get; set; } // New Field Added
}
그러나 아래 그림과 같이 새로운 필드가 전체 테이블에 대한 마이그레이션 클래스를 생성한다 :
추가 마이그레이션 또한
public partial class AddUserSetup_1 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "UserSetup",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
Name= table.Column<string>(nullable: false),
Age= table.Column<int>(nullable: false),
},
constraints: table =>
{
table.PrimaryKey("PK_UserSetup", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "UserSetup");
}
}
이 나에게 다음과 같은 오류를주고 있지만, 심지어 마이그레이션 클래스가 만들어지고 있습니다.
System.UnauthorizedAccessException : 'C : \ Projects \ PSM \ Portal \ src \ Portal \ Migrations \ ApplicationDbContextModelSnapshot.cs'경로의 액세스가 거부되었습니다.
감사합니다. Daniel. 감사합니다. – Vinay