Duplicate indices from migration

Duplicate indices from migration

Postby Developer » 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:

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;
        }


A sample of the Up() method:

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")


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?
Developer
 
Posts: 1
Joined: Fri 15 Sep 2017 15:18

Re: Duplicate indices from migration

Postby Pinturiccio » Fri 22 Sep 2017 13:39

Developer wrote:Setting the AddTableNameInDefaultIndexName property to true or false doesn't have any effect.

The AddTableNameInDefaultIndexName property does not affect index generation in the code. It affects the generation of indexes in the database, based on your code. If you run your project, the class name will be used in the database index name. This property is set to true by default, so you don't need to use it.
Pinturiccio
Devart Team
 
Posts: 1982
Joined: Wed 02 Nov 2011 09:44


Return to dotConnect for PostgreSQL