Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Add Migration Error

$
0
0

Hi there, 

I wondered if someone would be able to advise on a course of action for an error I'm getting when adding a Migration.

I add a class called Country containing the following properties:

        public int CountryId { get; set; }
        public string CountryName { get; set; }

I add two properties to the default ApplicationUser.cs file:

       public DateTime DateOfBirth { get; set; }
       public Country Country { get; set; }

I then go to do the migration in the PMC console:

Add-Migration date_name

However, it comes back with the following error:

An error occurred while calling method 'BuildWebHost' on class 'Program'. Continuing without the application service provider. Error: One or more errors occurred. (Invalid column name 'CountryId'.
Invalid column name 'DateOfBirth'.)
Unable to create an object of type 'ApplicationDbContext'. Add an implementation of 'IDesignTimeDbContextFactory<ApplicationDbContext>' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.

I have googled and found answers, however, they all relate to migrating from Core 1 to 2. I've compared the 'solutions' and my code seems fine.

If I remove the two properties from the ApplicationUser class then Migrations work again!

Can anyone advise on a solution, please?

Regards,

Dave.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>