Page 1 of 1
EFCore: DbContext.Database.EnsureCreated() can't create Database
Posted: Fri 18 Nov 2016 09:52
by dresel
Hi,
I'm using 7.6.763.0 of dcpostgresql76pro.
DbContext.Database.EnsureCreated() throw an "Database 'test' does not exist." exception instead of creating the database.
Code: Select all
class Program
{
static void Main(string[] args)
{
var context = new MyDbContext();
context.Database.EnsureCreated();
}
}
public class MyDbContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UsePostgreSql(@"Host=localhost;User Id=postgres;Password=postgres;Database=test;Unicode=true;");
}
}
Re: EFCore: DbContext.Database.EnsureCreated() can't create Database
Posted: Mon 21 Nov 2016 12:16
by Shalex
Please turn on the following option and try again:
Code: Select all
var config = Devart.Data.PostgreSql.Entity.Configuration.PgSqlEntityProviderConfig;
config.DatabaseScript.Schema.DeleteDatabaseBehaviour = Devart.Data.PostgreSql.Entity.Configuration.DeleteDatabaseBehaviour.Database;
For more information, refer to
https://www.devart.com/dotconnect/postg ... ation.html.
Re: EFCore: DbContext.Database.EnsureCreated() can't create Database
Posted: Thu 24 Nov 2016 07:47
by dresel
Well I was trying the
http://blog.devart.com/entity-framework ... 1479454278 blog post, there it says:
Additionally, our providers support only a part of provider configuration settings. For example, for config.DatabaseScript.Schema.DeleteDatabaseBehaviour setting, only the DeleteDatabaseBehaviour.ModelObjectsOnly value (default value) is supported.
Did you try your solution? Maybe I did something wrong, but
Code: Select all
static void Main(string[] args)
{
var config = Devart.Data.PostgreSql.Entity.Configuration.PgSqlEntityProviderConfig.Instance;
config.DatabaseScript.Schema.DeleteDatabaseBehaviour = Devart.Data.PostgreSql.Entity.Configuration.DeleteDatabaseBehaviour.Database;
var context = new MyDbContext();
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
}
still does not work.
Re: EFCore: DbContext.Database.EnsureCreated() can't create Database
Posted: Mon 28 Nov 2016 13:31
by Shalex
Your remark is correct, sorry for my mistake.
DeleteDatabaseBehaviour.Database is currently not supported for EF Core. We will notify you when the corresponding feature is implemented.
Re: EFCore: DbContext.Database.EnsureCreated() can't create Database
Posted: Fri 09 Dec 2016 19:24
by Shalex
The config.DatabaseScript.Schema.DeleteDatabaseBehaviour option is supported in EF Core:
viewtopic.php?f=3&t=34690.