Code First: Could not find file error after enable-migrations

When following the video “Demo -Code-first Workflow” I got the following error when running enable-migrations in the Package Manager Console:

PM> enable-migrations
Checking if the context targets an existing database...
System.IO.FileNotFoundException: Could not find file 'C:\Users\Arjen\Source\Repos\CodeFirstDemo\Migrations'.
File name: 'C:\Users\Arjen\Source\Repos\CodeFirstDemo\Migrations'
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost)
   at System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost)
   at System.Data.Entity.Tools.Commands.ProjectCommandBase.WriteMigration(ScaffoldedMigration scaffoldedMigration, Boolean rescaffolding, Boolean force, String name)
   at System.Data.Entity.Tools.Commands.MigrationsEnableCommand.Execute()
   at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
   at System.Data.Entity.Tools.Program.Main(String[] args)
Could not find file 'C:\Users\MyName\Source\Repos\CodeFirstDemo\Migrations'.

My connection string in App.config (which I took from the DatabaseFirstDemo App.config file):

    <add name="BlogDbContext" connectionString="data source=DESKTOP-I42Q9CK;initial catalog=CodeFirstDemo;integrated security=True;" providerName="System.Data.SqlClient"/>

Using VS Community 2019 and SQL Server 2019 Developer.

I believe the “Could not find file” error is a red herring. The line “Checking if the context targets an existing database…” takes a while and the path should have been created by the enable-migrations command.

However, if I skip the enamble-migrations command and simply run the application the database is successfully created (but, of course, no Migrations directory in the project directory).

Does anybody know how to solve this issue so that I can continue the Code-First part of the course?

After I de-installed SQL Server 2019 Developer and installed SQL Server Express I could run the following commands successfully:

PM> enable-migrations
Checking if the context targets an existing database...
Code First Migrations enabled for project CF_NewDB.
PM> add-migration InitialModel
Scaffolding migration 'InitialModel'.
The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration InitialModel' again.
PM> update-database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Applying explicit migrations: [202109290938475_InitialModel].
Applying explicit migration: 202109290938475_InitialModel.
Running Seed method.

I don’t know why this didn’t work with the Developer edition but at least for now I can continue with learning Code First.

I’m stuck here as well, but I get the following error when I run enable-migrations…

Enable-migrations : The term ‘Enable-migrations’ is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:2

  • Enable-migrations
  •  + CategoryInfo          : ObjectNotFound: (Enable-migrations:String) [], CommandNotFoundExce 
     + FullyQualifiedErrorId : CommandNotFoundException

I have no idea as he didn’t discuss any change to the project setup before starting this section. I dont know anything about SQL Server.

It is not the error message I got, but this is what I learned: make sure you use SQL Server Express and not any other SQL Server version.

It seems that Enable-migrations is deprecated and enabled by default. Try to use Add-Migration as mentioned here: EF Core tools reference (Package Manager Console) - EF Core | Microsoft Docs

Good luck!

ok thanks but where does the sql server express come in?

Sorry, that I cannot remember. It’s been over 4 months since I quit this course.

Ok I went to that tutorial and figured it out see below for anyone else struggling with this.

OK here goes…

  1. From the Tools menu, choose NuGet Package Manager , and then choose Package Manager Console .
  2. In the Package Manager Console window, enter the following command:
    Install-Package EntityFramework
    3.Create the DbContext
    in the models folder add a class called ApplicationDbContext paste in the following:
    using System.Data.Entity;
    using System.Data.Entity.ModelConfiguration.Conventions;

namespace Vidly.Models
public class ApplicationDbContext:DbContext
public DbSet Movies { get; set; }
public DbSet Customers { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)

4. From the Tools menu, select NuGet Package Manager > Package Manager Console .
At the PM> prompt enter the following commands:```
add-migration InitialCreate

Best wishes as the tutorial is missing key  instructions.  Very disappointing.
1 Like

That is a very good solution for your problem. Thanks for sharing it.
Good luck with the rest of the course.

very helpful thank you