• Register
0 votes
1.3k 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.

6 5 3
7,540 points

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 170 views
170 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 69 views
69 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 jwilliam 3.9k points
0 votes
1 answer 12 views
0 votes
1 answer 8 views
0 votes
1 answer 13 views