Code-First Migrations: Does not create Schema

Code-First Migrations: Does not create Schema

Postby dresel » Tue 08 Jul 2014 12:25

Hi,

when using Code-First with Migrations and another schema than public I get a "schema does not exist" Exception.

When using Code-First without Migrations the schema is created and everything works as intended.

Best Regards,
Dresel
dresel
 
Posts: 18
Joined: Tue 20 Nov 2012 13:38

Re: Code-First Migrations: Does not create Schema

Postby Shalex » Fri 11 Jul 2014 16:59

The "schema does not exist" error occurs when you use context.TestEntities.Create() with your sample from http://forums.devart.com/viewtopic.php?t=29842#p102684, doesn't it?
We cannot reproduce the issue with dotConnect for PostgreSQL v7.3.201. Please upgrade. If this doesn't help, give us the following information:
1) tell us how we should modify your sample for reproducing or send us a new small test project
2) which is SQL statement executed when the error occurs? (check via dbMonitor)
Shalex
Devart Team
 
Posts: 7774
Joined: Thu 14 Aug 2008 12:44

Re: Code-First Migrations: Does not create Schema

Postby dresel » Tue 15 Jul 2014 08:30

I have sent you the modified sample project.

I added the following to the context OnModelCreating:

Code: Select all
// Map to different schema
modelBuilder.Entity<TestEntity>().ToTable("TestEntity", "test");


I modified Migrations Down / Up to

Code: Select all
public override void Down()
{
   // Map to different schema
   DropTable("test.TestEntity");
}

public override void Up()
{
   Console.WriteLine("Migrations called.");

   // Map to different schema
   CreateTable("test.TestEntity",
      c => new { TestEntityID = c.Int(nullable: false, identity: true), TestEntityText = c.String(), })
      .PrimaryKey(t => t.TestEntityID);
}
dresel
 
Posts: 18
Joined: Tue 20 Nov 2012 13:38

Re: Code-First Migrations: Does not create Schema

Postby Shalex » Thu 17 Jul 2014 17:32

Thank you for the report. We have reproduced the issue and are investigating it.
Shalex
Devart Team
 
Posts: 7774
Joined: Thu 14 Aug 2008 12:44

Re: Code-First Migrations: Does not create Schema

Postby Shalex » Tue 12 Aug 2014 16:37

In scope of current EF 6.1 architecture, we are limited in ability to process the scenario of creating database with the help of migrations because we do not have information about mapped objects of EF model in the moment of creating database with CreateDatabase() functionality. The only information we have access to is PgSqlConnection and its connection string.
So we create a database, specified in the Database connection string parameter, and a schema(s), which is set in the Schema connection string option.
And when DDL for migration is generated, we already do not have access to the actual connection.

A solution in this scenario is to enumerate all needed schemas in the Schema connection string parameter. For example, specify "schema=public,test;" instead of "schema=public;" in your connection string.
Shalex
Devart Team
 
Posts: 7774
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for PostgreSQL