7

I was adding a migration in my ASP.NET Core project using EF Core 2.0. I ran the 'Add-Migration 'migrationName` command in my package manager console. The migration was successfully added to my migrations folder, however, while trying to update the snapshot I got this error:

Access to the path 'C:\path\to\snapshot\DbContextModelSnapshot.cs' is denied.

Right now I have a new migration in my migration folder but an old snapshot because it can't be updated at the moment. The migrations are saved in the same folder as the snapshot and all users have read/write access to the folder.

How do I fix this?

Welz
  • 236
  • 2
  • 10
  • 21
Jeroen
  • 1,625
  • 3
  • 16
  • 28

2 Answers2

8

I wild guess: You have your solution under TFS source control, with server workspace. After you initially checked in your code, the file became read-only. Seems like PM doesn't checkout the files (or add the migration files) to source control automatically. So in order to fix this: Before running the command, checkout the snapshot, and after running the migration add the newly generated files to source control.

macwier
  • 1,063
  • 1
  • 6
  • 19
  • I checked the snapshot out for editing before running the migration and now it works. You are right I am working with TFS using server workspace. I once changed my workspace from local to server because of performance reasons, I might reconsider this now. – Jeroen Mar 15 '18 at 10:35
2

I have faced with same situation.

Access to the path 'C:\repos\ProjectName\Migrations\ProjectNameDbContextModelSnapshot.cs' is denied.

Just right clicked file projectDbContextModelSnapshot.cs with Windows Explorer and saw there was Read-Only flag, and removed this checkbox. Problem solved.

Alakbar
  • 41
  • 5