首页 > 解决方案 > dotnet ef 迁移添加引发异常

问题描述

我在 MacOS 终端中使用以下命令;

dotnet ef migrations add Student --project

并得到异常“索引超出了数组的范围。”

User-MacBook-Pro WebAPITutorial % dotnet ef migrations add Student --project
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.ParseOption(Boolean isLongOption, CommandLineApplication command, String[] args, Int32& index, CommandOption& option)
   at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
   at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
Index was outside the bounds of the array.

请帮帮我。

标签: .netvisual-studioentity-framework.net-core

解决方案


您忘记指定项目名称(如果要将您的迁移存储在与包含您的项目不同的项目中DbContext):

dotnet ef migrations add Student --project YourProjectName

或者如果您在项目目录中,则无需指定项目名称:

dotnet ef migrations add Student

推荐阅读