Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 尝试首先更新数据库代码时出错_C#_Sql Server_Asp.net Mvc_Ef Code First_Entity Framework Migrations - Fatal编程技术网

C# 尝试首先更新数据库代码时出错

C# 尝试首先更新数据库代码时出错,c#,sql-server,asp.net-mvc,ef-code-first,entity-framework-migrations,C#,Sql Server,Asp.net Mvc,Ef Code First,Entity Framework Migrations,在数据库中添加了一些需要作为表的类之后,我试图更新我的数据库 我得到以下错误: There is already an object named 'Blogs' in the database. 我的数据上下文如下所示最后3行是我需要添加到数据库中的表: public class WowDataContext : DbContext { public WowDataContext() : base("name=DefaultConnection") { }

在数据库中添加了一些需要作为表的类之后,我试图更新我的数据库

我得到以下错误:

There is already an object named 'Blogs' in the database.
我的数据上下文如下所示最后3行是我需要添加到数据库中的表:

public class WowDataContext : DbContext
{
    public WowDataContext()
        : base("name=DefaultConnection")
    { }
    public DbSet<Genre> Ganres { get; set; }
    public DbSet<TakeAway> TaKeAways { get; set; }

    public DbSet<Gellery> Galleries { get; set; }
    public DbSet<katering> Katring { get; set; }
    public DbSet<Blog> Blogs { get; set; }
    public DbSet<Events> events { get; set; }
    //i need to add this folowing 3 tables
    public DbSet<Order> orders { get; set; }
    public DbSet<OrderDetail> OrderDetails { get; set; }
    public DbSet<Cart> Carts { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
    }
}
孔更新数据库如下所示:

[

我的数据库迁移看起来像这样 ![迁移表][2]`

您可以尝试以下方法:

删除migrations文件夹中的所有迁移小心-不要删除配置类文件 运行addmigration命令 运行更新数据库命令 如果这不起作用,并且是在测试环境中,那么您还可以执行以下操作:

删除您的数据库 删除migrations文件夹中的所有迁移小心-不要删除配置类文件 运行addmigration命令 运行更新数据库命令
您需要运行“更新数据库”命令。是的,我已尝试过此操作,我还重新运行了此操作:添加迁移201403251531583\u InitialCreate重新搭建迁移“201403251531583\u InitialCreate”。仅重新搭建了迁移“201403251531583\u InitialCreate”的设计器代码。若要重新搭建整个迁移,请使用-Force参数。。这没用