The string argument 'migrationId' cannot be empty

雨燕双飞 提交于 2019-12-10 20:33:07

问题


Apologies in advance if this has already been answered but I've honestly dug deep and could not find anything relating to this error.

In a nutshell, I am unable to make any updates to my database using code first within my ASP.NET Core 1.1.2 project. It's throwing an exception because it's missing an argument which I'm guessing is not to do with PMC.

Error message when using 'Update-Database':

Text for cross checking Google ;-)

    System.ArgumentException: The string argument 'migrationId' cannot be empty.
   at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(String value, String parameterName)
   at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.GetAppliedMigrations()
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_1.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
The string argument 'migrationId' cannot be empty.

The Migrations folder is identical to my '_EFMigrationsHistory' table (ignoring the last migration which is scheduled for update):

I've even gone as far as removing the Migrations folder and '_EFMigrationsHistory' table and starting again which presented the same error. I was also going to test 'v2.0.0-preview2-final' just in case it was a bug, but sadly my version of VS only takes release builds and apparently you need 15.3.

Version Info:

  • Visual Studio Enterprise 2017 - 15.2 (26430.16) Release
  • Entity Framework Core v1.1.2
  • ASP.NET Core v1.1.2

Any pointers would be much appreciated.

Edit

@DavidG

For dotnet ef database update

and for Update-Database -TargetMigration AdUserImage


回答1:


I finally resolved the issue thanks to @DavidG putting me on the right direction so thank you very much.

I realised that when I was checking the installed SDK's on my PC, I noticed that I've installed a pre-release of Dotnet 2.0.0 (I honestly can't remember doing this). Checking the Dotnet version (dotnet --version) from PMC confirmed VS was using 2.0.0. After uninstalling all Dotnet SDK's and runtimes and then re-installing the latest release of Dotnet(1.1.2) from here, Update-Database was working as should...few!



来源:https://stackoverflow.com/questions/45282303/the-string-argument-migrationid-cannot-be-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!