1

I deleted an attribute in model of codefirst asp.net core project, and use update-databae -verbose but did not delete the attribute from table of database. Then I used update-database -verbose -force command, but received an error that it did not recognize -force.

kosist
  • 2,868
  • 2
  • 17
  • 30
sadegh
  • 19
  • 1
  • 10

1 Answers1

1

Entity framework core update-database command does not have -force parameter. It's only available for remove-migration and Scaffold-DbContext commands.

You can find a complete list of commands here.

You can use Scaffold-DbContext command with -force. This way you can force scaffolding to overwrite existing model files. Be cautious when using this command.

Scaffold-DbContext "<ConnectionString>" Microsoft.EntityFrameworkCore.SqlServer -tables <tablename> -force
itsMasoud
  • 1,335
  • 2
  • 9
  • 25
  • with this code received this error. please help me. For foreign key FK_HstJudge_IssuerHeadOffice_IssuerHeadOfficeId on table dbo.HstJudge, unable to model the end of the foreign key on principal table dbo.IssuerHeadOffice. This is usually because the principal table was not included in the selection set. – sadegh Nov 04 '19 at 05:54
  • I've never faced this issue before and for solving this kind of issues you need to know more details about schema, models, and..., but [here](https://stackoverflow.com/q/57485837/12217161) you can find a similar problem. If it didn't help, please ask a new question and present more details in it. If you have **multiple schemas** in your project, [here](https://stackoverflow.com/q/11197754/12217161) you can find a proper workaround to prevent future issues. – itsMasoud Nov 04 '19 at 11:30