이 질문은 여러 가지 맛으로 여러 번 묻습니다. 나는 모든 대답을 끝내고 많은 시간을 불 태웠다. 나는이 일을 할 수없는 것 같습니다.코드 처음 마이 그 레이션 - 엔티티 프레임 워크 - 테이블에 열을 추가 할 수 없습니다.
나는 asp.net mvc Entity Framework, SQL 서버 응용 프로그램에서 작업 해 왔습니다. 나는 이미 기존 데이터베이스, 테이블 등을 가지고 있으며 모든 것이 작동 중이다. 테이블에 새 열을 추가하기 만하면됩니다.
그래서 .. 테이블에 열을 추가 할 수 있도록 모델 클래스에 속성을 추가했습니다. 그러나 성공하지 못했습니다.
그래서 다음 순서로 단계를 수행합니다.
내 모델 클래스에 필드를 추가하십시오.
[Required] public string EmailSubject{ get; set; }
- 가 그럼 난 패키지 관리자 콘솔에서 다음
Configuration.cs 클래스
을 포함하는 내 asp.net MVC 프로젝트의 폴더 마이그레이션을 삭제, 나는 성공적 명령을 다음 문제.
- 가 그럼 난 패키지 관리자 콘솔에서 다음 명령을 실행하여 다음과 같이
Enable-Migrations -ContextTypeName AppointmentReminder.Data.ReminderDb -Force
- 은 그 때 나는 진정한 속성을 설정합니다. 여기
Update-Database -Verbose -Force
public Configuration()
{
AutomaticMigrationsEnabled = true;
}
내 연결 문자열은 내가 원하는 테이블에 새 열을 추가 할 수 없습니다입니다하지만
Data Source=(LocalDb)\v11.0;AttachDbFilename=C:\practice\AppointmentReminder4\AppointmentReminder4\App_Data\aspnet-AppointmentReminder4-20141202060615.mdf;Initial Catalog=aspnet-AppointmentReminder4-20141202060615;Integrated Security=True
같은 데이터베이스에 연결이 보이는 기본값 것입니다.
편집에 필요한 특성이없는 다음과 위의 모든 단계를 실행하지만 난 여전히 테이블에 열을 추가 할 수 없습니다 나는 모델을 업데이트 한
.
public string EmailBody { get; set; }
다음은 모든 명령과 출력입니다. 2
PM> Enable-Migrations -ContextTypeName AppointmentReminder.Data.ReminderDb -Force
Checking if the context targets an existing database...
Code First Migrations enabled for project AppointmentReminder4.
PM> Update-Database -Verbose -Force
Using StartUp project 'AppointmentReminder4'.
Using NuGet project 'AppointmentReminder4'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is: 'aspnet-AppointmentReminder4-20141202060615' (DataSource: (LocalDb)\v11.0, Provider: System.Data.SqlClient, Origin: Configuration).
No pending explicit migrations.
Running Seed method.
PM> Update-Database -Verbose -Force
Using StartUp project 'AppointmentReminder4'.
Using NuGet project 'AppointmentReminder4'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is: 'aspnet-AppointmentReminder4-20141202060615' (DataSource: (LocalDb)\v11.0, Provider: System.Data.SqlClient, Origin: Configuration).
No pending explicit migrations.
Running Seed method.
PM>
편집 마지막으로이 문제를 해결. 위의 모든 단계가 정확했습니다. ReminderDb (EF 객체)에 실제로 연결된 실제 데이터 클래스와 달리 모델 클래스를 편집하는 것을 제외하고는. 속성으로 올바른 클래스를 업데이트 한 후에는 모든 것이 성공적으로 수행되었습니다. 도움을 받아 응답 한 모든 사람들에게 감사드립니다!
, 당신은 아마 표시해야합니다 어떤 오류를 알았어. –