• Register
0 votes
3.2k views

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.

7.5k 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.

38.6k points

Related questions

0 votes
1 answer 73 views
73 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 347 views
347 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 421 views
421 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 10 views
10 views
Problem: Windows 10 lock screen slideshow doesn't work.
asked Jul 7 Florina Gulnar 106k points
0 votes
1 answer 9 views
9 views
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 Apr 12 ummesalma 29.1k points
0 votes
1 answer 71 views
71 views
Problem: I have used android view pager to display images and text now what i want is that if a user is not changing the images then it should start to change the images automatically after a few seconds and when the user again starts using his finger then the images should not change automatically?
asked Apr 19 ummesalma 29.1k points
0 votes
1 answer 53 views
53 views
Problem: Is there any way to solve this? > Executereader: connection property has not been initialized.
asked May 8 Irenka Kiri 85.5k points
0 votes
1 answer 41 views
41 views
Problem: What should I do if I can't find a solution anywhere : Hyper-v cannot be installed virtualization support is disabled in the firmware?
asked Jun 14 Mezbah 130k points
0 votes
1 answer 14 views
14 views
Problem: I am stuck with this ... Please help me that how to deal with this? hyper-v cannot be installed virtualization support is disabled in the firmware
asked Apr 4 Ifra 43.4k points
0 votes
1 answer 88 views
88 views
Problem: what is wronge with this ? how can i fix it ? build completed with a result of 'failed' unityengine.guiutility:processevent(int32, intptr).
asked Mar 6 Wafa Abu Yousef 6.1k points