我尝试运行代码库实体框架迁移。当运行“add-migration”命令时,我总是会收到此错误(初始迁移除外):由于以下显式迁移未决,因此无法生成显式迁移:[201607141552034_Add_storeId_firstname_to_customer]。在尝试生成新的显式迁移之前应用挂起的显式迁移。但是,如果我尝试运行“update-database -Verbose -ConnectionStringName”ZzaDbConnectionString“,我会收到一个非常令人困惑/冲突的错误:没有待定的显式迁移。我尝试删除迁移文件,然后使用add-migration再次创建它。它只工作一次。下次(例如,如果我想在我的表中添加一列),我得到了同样的错误。有什么建议问题吗?谢谢。
编辑:添加代码和配置。
这是实体类。
namespace Zza.Entities
{
public class Customer
{
public Guid Id { get; set; }
[MaxLength(50)]
public string FullName { get; set; }
}
}
这是Context类:
namespace Zza.Data
{
public class ZzaDbContext : DbContext
{
public DbSet<Customer> Customers { get; set; }
}
}
这是控制台类:
namespace TestEFMigration
{
public class Program
{
static void Main(string[] args)
{
CreateDataBase();
}
private static void CreateDataBase()
{
var context = new ZzaDbContext();
context.Database.Initialize(false);
}
}
}
context class的app.config
<add name="ZzaDbConnectionString"
connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Zza;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
providerName="System.Data.SqlClient" />
控制台的app.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<connectionStrings>
<add name="ZzaDbConnectionString" connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Zza;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
iceheart