This problem happens even when using the CrmDemo located here: http://blogs.devart.com/dotconnect/enti ... irstsample
When running with EF 4.1 everything seems to work fine. When using EF 4.4 or 5.0 (upgraded using NuGet, I have to fix the references and using statements so the demo compiles) I get the given error after I run the program once: relation "__MigrationHistory" already exists.
The first time I run when the DB is empty everything appears to work fine and the __MigrationHistory table is created. After that I get the error every time. Other than upgrading Entity Framework and adding the necessary using directive, I have made no changes. I get the same problems in the my test projects.
I am using VS 2010 and PostgreSQL 9.1.5.
Any recommendations to fix this issue?
relation "__MigrationHistory" already exists error when attempting to use EF Code First with PostgreSQL
Re: relation "__MigrationHistory" already exists error when attempting to use EF Code First with PostgreSQL
Thank you for your report. We have reproduced and are investigating the issue. As a temporary workaround, please turn off the database initialization strategy, i.e. comment the following line in the MyPgSqlContext.cs file:
We will post here when the issue is fixed.
Code: Select all
System.Data.Entity.Database.SetInitializer<MyPgSqlContext>(new MyDbContextDropCreateDatabaseAlways());
Re: relation "__MigrationHistory" already exists error when attempting to use EF Code First with PostgreSQL
Starting from EFv4.3, the behaviour was changed: Drop must clear/remove all content of the database. So the DropCreateDatabaseAlways and DropCreateDatabaseIfModelChanges strategies can be used only with DeleteDatabaseBehaviour which is equal to AllSchemaObjects or Schema:
OR
We will update our blog article correspondingly.
Code: Select all
var config = Devart.Data.PostgreSql.Entity.Configuration.PgSqlEntityProviderConfig.Instance;
config.DatabaseScript.Schema.DeleteDatabaseBehaviour = DeleteDatabaseBehaviour.AllSchemaObjects;
Code: Select all
var config = Devart.Data.PostgreSql.Entity.Configuration.PgSqlEntityProviderConfig.Instance;
config.DatabaseScript.Schema.DeleteDatabaseBehaviour = DeleteDatabaseBehaviour.Schema;