【问题标题】:Entity Framework: enable-migrations in package management console does not work实体框架:包管理控制台中的启用迁移不起作用
【发布时间】:2019-10-04 09:57:12
【问题描述】:

我在 VisualStudio 2019 中创建了一个非常简单的项目,以使用实体框架(代码优先)创建一个数据库。数据库也已创建,我可以添加记录(请参阅 PrintScreen)。 当我现在尝试在包管理器控制台中执行“启用迁移”时,我总是收到一条错误消息:

enable-migrations : Das Argument kann nicht an den Parameter "Path" gebunden werden, da es NULL ist.
In Zeile:1 Zeichen:1
+ enable-migrations
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Enable-Migrations], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Enable-Migrations

我已经尝试在所有变体和所有可能的参数中调用“启用迁移” - 不幸的是总是得到相同的结果。我还以“管理员”身份启动了 Visual Studio 2019 - 这也不起作用。

目前有效的程序:

using System;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;

namespace EntityTest
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Kunde kunde = new Kunde { Name = "MyTestName" };
            using (var context = new EntityTestDbContext())
            {
                context.Kunden.Add(kunde);
                context.SaveChanges();
            }
        }
    }

    public class EntityTestDbContext : DbContext
    {
        public const string DbConn = "Data Source=(localdb)\\mssqllocaldb;Initial Catalog=EntityTest; Integrated Security=True; MultipleActiveResultSets=True";
        public EntityTestDbContext() : base(DbConn)
        {
        }

        public DbSet<Kunde> Kunden { get; set; }
    }

    public class Kunde
    {
        [Required, Key]
        public int KuId { get; set; }
        [StringLength(100)]
        public string Name { get; set; }
    }
}

Visual Studio screenshot with all relevant outputs

【问题讨论】:

  • 请检查PackageManagerConsole的对话框中是否选择了正确的项目
  • 是的,已经完成了 - 另见屏幕截图。

标签: c# visual-studio entity-framework


【解决方案1】:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-15
    • 2013-06-01
    • 1970-01-01
    • 2021-12-09
    • 2018-04-06
    相关资源
    最近更新 更多