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

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 107 views
107 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 258 views
258 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 12 views
0 votes
1 answer 11 views
11 views asked Oct 3, 2020 miki 1.9k points
0 votes
1 answer 17 views
0 votes
1 answer 9 views
9 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.2k points
0 votes
1 answer 13 views
13 views
I have a hash of words and respective frequencies, that I want to order by frequency. Sorted Dictionary orders by key, not value. Some resort to a custom class, but is there a cleaner way?
asked Aug 31, 2020 Sofi55 1.1k points
0 votes
1 answer 63 views
63 views
In previous versions of .Net, it was possible to override bool AuthorizeCore(HttpContextBase httpContext). But this no longer exists in AuthorizeAttribute. What is the current approach to making a custom AuthorizeAttribute?
asked Aug 29, 2020 Aliza313 720 points
1 vote
1 answer 271 views
271 views
Problem : I have recently developed one page which I guess takes more time to load in the asp.net website. My page currently works with all the Android OS, all of the MAC OS and all iOS but it fails with iOS with version 10.0.0.2 with only safari browser. If I ... the DNS server Tried the Airplane mode on-off Also did my iPhone restart But still unable to fix it. Can someone help me in fixing it?
asked Apr 1, 2020 morrisBson 3.2k points