ERROR: 42P01: relation "dbo.__MigrationHistory" does not exist
但我相信这只是因为之前的某些设置没有正确地设置。
我目前正在尝试使用Npgsql 2.0.12来设置实体框架4.4的Code First。我已经完成了以下步骤,现在至少似乎可以连接到数据库,但是当我进行context.saveChanges();时会出现上述错误。
Updated the machine.config for .net 2.0.50727 with;
< add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql Server" type="Npgsql.NpgsqlFactory, Npgsql, Version=2.0.12.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />
Added the dlls to the project
Changed the app.config to look like this;
<configuration> <configSections> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </configSections> <system.data> <DbProviderFactories> <remove invariant="Npgsql"></remove> <add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Framework Data Provider for Postgresql Server" type="Npgsql.NpgsqlFactory, Npgsql, Version=2.0.12.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" /> </DbProviderFactories> </system.data> <connectionStrings> <add name="DataContext" connectionString="Server=127.0.0.1;Port=5432;Database=postgres;User Id=postgres;Password=*******;CommandTimeout=20;" providerName="Npgsql" /> </connectionStrings> </configuration>
Data passing in looks like the following
public class Animal { [Key] public int Id { get; set; } public string Name { get; set; } public string Description { get; set; } public int Age { get; set; } public int NoOfLegs { get; set; } }
Everything else is generic off the shelf set up of contexts
附注:对于错误的代码格式化对不起,由于某种原因,堆栈交换不允许我正确使用它,即使它已经正确格式化。
1.InitializeDatabase(TContext context)处 在System.Data.Entity.Database.<>c__DisplayClass2
1.<SetInitializerInternal>b__0(DbContext c)" - Ankou