我正在使用EF 6.1和我在我的项目中启用代码第一次迁移
Enable-Migrations Add-Migration InitializeDb -ConnectionProviderName System.Data.sqlClient -ConnectionString "Data Source=myServer;Initial Catalog=myDb;Persist Security Info=True;User ID=sa;password=******;application name = L4" Update-Database -ConnectionProviderName System.Data.sqlClient -ConnectionString "Data Source=myServer;Initial Catalog=myDb;Persist Security Info=True;User ID=sa;password=******;application name = L4" -verbose -script
当我在包管理器控制台中使用Add-Migration和Update-database明确指定了ConnectionString ConnectionProviderName
它正常工作:
Add-migration updateXtable -ConnectionProviderName System.Data.sqlClient -ConnectionString "Data Source=myServer;Initial Catalog=myDb;Persist Security Info=True;User ID=sa;password=******;application name = L4"
但是当我使用Add-Migration而不需要额外的信息时:
add-migration updateXtable
我得到以下错误:
@H_502_15@Unable to generate an explicit migration because the following explicit migrations are pending: [201408300955376_InitializeDb,201408311028404_Test]. Apply the pending explicit migrations before attempting to generate a new explicit migration.
所以,每次我需要更新我的数据库时,我必须使用以下命令:
Add-Migration UpdateXTable -ConnectionProviderName System.Data.sqlClient -ConnectionString "Data Source=myServer;Initial Catalog=myDb;Persist Security Info=True;User ID=sa;password=******;application name = L4" Update-Database -ConnectionProviderName System.Data.sqlClient -ConnectionString "Data Source=myServer;Initial Catalog=myDb;Persist Security Info=True;User ID=sa;password=******;application name = L4" -verbose -script
这是我的项目(包含我的DbContext)app.config文件:
<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version=6.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </configSections> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.sqlConnectionFactory,EntityFramework" /> <providers> <provider invariantName="System.Data.sqlClient" type="System.Data.Entity.sqlServer.sqlProviderServices,EntityFramework.sqlServer" /> </providers> </entityFramework> <connectionStrings> <add name="ERPContext" connectionString="Data Source=myServer;Initial Catalog=myDb;Persist Security Info=True;User ID=sa;password=******;application name = L4" providerName="System.Data.sqlClient" /> </connectionStrings> <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /> </startup> </configuration>
有谁知道问题在哪里?