• Register
0 votes

Problem :

My DbContext class defined the principal entity as below.

HasOne(b => b.Customer).WithOne(c => c.BankAccount).HasForeignKey<BankAccount>(f => f.Id);

But while running the update-database I am getting the following error:

 System.InvalidOperationException: To change the IDENTITY property of a column, the column needs to be dropped and recreated.

But ideally I should not get it but just get rid of this error. I have deleted the column, constraints and table as well and then the complete database also. But still I am getting the same error.

6 5 3
7,540 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

I also had faced this issue when I tried to change my model from public byte Id {get; set;} to public int Id {get; set;}. To solve the issue, I did the following things:

1.  Removed all the migrations until the creation of the target model with Remove-Migration -Project <target_project> command in the Package Manager Console

2.  Deleted the actual database

3.  If you are having some migrations in the middle that you have not created for instance they are from another branch then copy the migrations files and also the ModelSnapshot file and paste them in your branch very carefully!

4.  created a new migration with add-migration <migration_name> command in the Package Manager Console

5.  updated the database with update-database command in the Package Manager Console

I was able solve the issue in this way as my code was not in a production environment.

9 7 4
38,600 points

Related questions

0 votes
1 answer 14 views
Problem: Any ideas on what I need to do to fix this? To change the identity property of a column, the column needs to be dropped and recreated..
asked Mar 7 Wafa Abu Yousef 6.1k points
0 votes
1 answer 151 views
Problem : I want to select a maximum avg for each cname in my table. SELECT cname, wmname, MAX(avg)  FROM makerar GROUP BY cname; But I will get the below error, ERROR:  column "makerar.wmname" must appear in the GROUP BY clause or be used in an   aggregate ... )  FROM makerar GROUP BY cname; How can I go about fixing above error? Note: This table is the VIEW created from the previous operation.
asked Jan 22, 2020 jwilliam 3.9k points
0 votes
1 answer 1 view
1 view
Problem: I recently upgraded my Windows 7 machine to Windows 8.1 to be capable of developing Windows Store apps using Visual Studio 2013. When I open a blank project (Windows Store -> Blank App) and run it I get this error: Unable to activate Windows Store app 'Package Name'. The App1.exe process started, but the activation request failed with error 'The app didn't start'
asked 20 hours ago ummesalma 24.5k points
0 votes
1 answer 319 views
Problem : I have facing an issue with my C# PayTrace Gateway. My code was working fine until they turned off SSL3 due to the Poodle Exploit. When tried running my code I am getting the following message: The remote server has forcefully closed the connection. ... The client and server cannot communicate, because they do not possess a common algorithm. Any clue on error messages which I am facing?
asked Nov 29, 2019 alecxe 7.5k points
0 votes
1 answer 21 views
0 votes
1 answer 128 views
Problem: I am completely new to ASP .net core. I guess it is giving me the dependency injection error as shown below: InvalidOperationException: Unable to resolve service for type 'Spinit ... ) Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext) Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
asked Aug 17, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 12 views
Problem I would like understand the difference between ASP.NET Core and, so called, ordinary ASP.NET. I have significant experience programming ASP.NET and I had an opportunity to take a look on ASP.NET Core project and it feels like completely different creature.
asked Nov 27, 2020 alexh 2.6k points
0 votes
1 answer 14 views
14 views asked Oct 3, 2020 miki 1.9k points
0 votes
1 answer 25 views
Problem: system.componentmodel.win32exception: the network path was not found.
asked Feb 12 Shovo210 13.3k points