Search code examples
entity-frameworkentity-framework-6npgsql

PostgresException: 3D000: database 'xx' does not exist


I'm attempting to run an EF migration against my PostgreSQL database using Npgsql and code that's similar to what I've used in other projects:

var applicationContextOption = CreateContextOption<ApplicationDbContext>(connectionString, loggerFactory);

using ApplicationDbContext context = new(applicationContextOption.Options, null);
context.Database.Migrate();

While I'm used to context.Database.Migrate() creating the database if it doesn't exist, I'm instead getting the following error at runtime:

PostgresException: 3D000: database "xx" does not exist.

I tried restarting VS2022 and tried restarting my computer, and I've tried Cleaning and Rebuilding the solution, but I still got the same result every time. I believe I may have gotten the migration to run successfully in the past without issue, but I'm not certain. I can't find anything specific to this project that would be causing the issue.


Solution

  • Deleting the .vs folder in the solution directory worked for me. After deleting the folder, I was able to run the migrations without issue.

    By deleting the .vs folder, any solution-level settings (open tabs, breakpoints, probably bookmarks) are lost, unfortunately, but I haven't determined what the minimum subset of files is that can be deleted to resolve the issue.