Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access denied to ContextModelSnapshot while migrating

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?

like image 396
Jeroen Avatar asked Mar 13 '18 11:03

Jeroen


People also ask

Why does the migration agent fail to install?

The parent folder was not migrated, therefore all items under the folder will fail to migrate. Check your parent folder and retry your migration. Issue: The migration agent fails to install when using an old version of agent setup file to install agent. The problem could be caused by an outdated clientsetup.exe file.

Why am I getting HTML error codes in my migration error reports?

Migration errors Google migration error reports contain HTML Error codes Check prerequisites and settings Make sure you have met the prerequisites for agent installation, and have reviewed the required endpoints.

Why does Migration Manager cache my package on the working folder?

0x02040012 The temporary storage on your local computer is too low. Migration Manager caches the package on the working folder. Expand your temporary storage and retry. 0x02030003

Why can't I open the source file in the migration?

The disk space available for the migration working folder is too small for the size of your source file. Enlarge your size of your working folder try again. Packaging failure: Cannot open file Packaging failed due to non-existing source. Check if you can access the source root folder. A duplicate task has already been created.


2 Answers

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.

like image 176
Botis Avatar answered Sep 20 '22 13:09

Botis


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.

like image 42
Alakbar Avatar answered Sep 17 '22 13:09

Alakbar