Duplicate indices from migration
Posted: Fri 15 Sep 2017 15:42
In my current project we use code-first and we can succesfully create a database. Now we try to introduce migrations. Assuming we start with an empty database, when we create an initialCreate migration, we end up with a lot of duplicate index names (e.g. IX_Id and IX_Model_Id) for the different tables. Setting the AddTableNameInDefaultIndexName property to true or false doesn't have any effect.
The configuration file is:
A sample of the Up() method:
Especially since a database could already be created succesfully before we tried to use migrations, we suspect the problem to be in the PgSqlEntityMigrationSqlGenerator. We updated to version 7.9.980.0 of PostgreSql.Entity EF6, but that didn't solve the problem.
How could we make sure that indices are created unique automatically using the table name?
The configuration file is:
Code: Select all
public Configuration()
{
AutomaticMigrationsEnabled = false;
SetSqlGenerator(PgSqlConnectionInfo.InvariantName, new PgSqlEntityMigrationSqlGenerator());
var config = Devart.Data.PostgreSql.Entity.Configuration.PgSqlEntityProviderConfig.Instance;
config.CodeFirstOptions.AddTableNameInDefaultIndexName = true;
}
Code: Select all
CreateTable(
"dbo.Users",
c => new
{
id = c.Guid(nullable: false),
client_id = c.Guid(),
name = c.String(),
})
.PrimaryKey(t => t.id)
.ForeignKey("dbo.Clients", t => t.client_id)
.Index(t => t.id, name: "IX_Id")
.Index(t => t.client_id, name: "IX_Client_Id");
CreateTable(
"dbo.Scenes",
c => new
{
id = c.Guid(nullable: false),
client_id = c.Guid(),
name = c.String(maxLength: 450)
})
.PrimaryKey(t => t.id)
.ForeignKey("dbo.Clients", t => t.client_id)
.Index(t => t.id, name: "IX_Id")
.Index(t => t.client_id, name: "IX_Client_Id")
How could we make sure that indices are created unique automatically using the table name?