Code-First Migrations: Index names problem

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
gustavo.cruz
Posts: 1
Joined: Thu 10 Oct 2013 19:43

Code-First Migrations: Index names problem

Post by gustavo.cruz » Fri 14 Mar 2014 17:41

Hi,

I have an entity that references two other entities in a Many-To-Many relationship.

When I try to run the "Update-Database" in the console, i get an exception with the Index name of the created tables. The problem is that the index name of the relation table (middle table) are the same in both tables, because the relation references the same table (two N-N relationship referencing the same table)

The migrations generated code is:

Code: Select all

public override void Up()
        {
            CreateTable(
                "dbo.Especialidade",
                c => new
                    {
                        IdEspecialidade = c.Int(nullable: false, identity: true),
                        Codigo = c.String(nullable: false, maxLength: 15),
                        Nome = c.String(nullable: false, maxLength: 60),
                    })
                .PrimaryKey(t => t.IdEspecialidade);
            
            CreateTable(
                "dbo.Procedimento",
                c => new
                    {
                        IdProcedimento = c.Int(nullable: false, identity: true),
                        Codigo = c.String(nullable: false, maxLength: 30),
                        Nome = c.String(nullable: false, maxLength: 80),
                    })
                .PrimaryKey(t => t.IdProcedimento);
            
            CreateTable(
                "dbo.GrupoProcedimento",
                c => new
                    {
                        IdGrupoProcedimento = c.Int(nullable: false, identity: true),
                        Codigo = c.String(nullable: false, maxLength: 15),
                        Nome = c.String(nullable: false, maxLength: 80),
                    })
                .PrimaryKey(t => t.IdGrupoProcedimento);
            
            CreateTable(
                "dbo.ProcedimentoEspecialidades",
                c => new
                    {
                        IdProcedimento = c.Int(nullable: false),
                        IdEspecialidade = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.IdProcedimento, t.IdEspecialidade })
                .ForeignKey("dbo.Procedimento", t => t.IdProcedimento, cascadeDelete: true)
                .ForeignKey("dbo.Especialidade", t => t.IdEspecialidade, cascadeDelete: true)
                .Index(t => t.IdProcedimento)
                .Index(t => t.IdEspecialidade);
            
            CreateTable(
                "dbo.ProcedimentoGrupos",
                c => new
                    {
                        IdProcedimento = c.Int(nullable: false),
                        IdGrupoProcedimento = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.IdProcedimento, t.IdGrupoProcedimento })
                .ForeignKey("dbo.Procedimento", t => t.IdProcedimento, cascadeDelete: true)
                .ForeignKey("dbo.GrupoProcedimento", t => t.IdGrupoProcedimento, cascadeDelete: true)
                .Index(t => t.IdProcedimento)
                .Index(t => t.IdGrupoProcedimento);
            
        }
The code above creates TWO index with the SAME NAME: "IX_IdProcedimento".

Is there any way to workaround this?



Here is the full exception generated by Migrations:

Code: Select all

PM> Update-Database -Verbose
Using StartUp project 'PDev.Infrastructure'.
Using NuGet project 'PDev.Infrastructure'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Target database is: '' (DataSource: DESENV, Provider: Devart.Data.Oracle, Origin: Configuration).
Applying explicit migrations: [201403141445405_Add_Procedimento].
Applying explicit migration: 201403141445405_Add_Procedimento.
CREATE TABLE "Especialidade" ( 
  "IdEspecialidade" NUMBER(10) NOT NULL,
  "Codigo" NVARCHAR2(15) NOT NULL,
  "Nome" NVARCHAR2(60) NOT NULL,
  PRIMARY KEY ("IdEspecialidade")
)
CREATE SEQUENCE "Especialidade_SEQ"
CREATE OR REPLACE TRIGGER "Especialidade_INS_TRG"
  BEFORE INSERT ON "Especialidade"
  FOR EACH ROW
BEGIN
  SELECT "Especialidade_SEQ".NEXTVAL INTO :NEW."IdEspecialidade" FROM DUAL;
END;
CREATE TABLE "Procedimento" ( 
  "IdProcedimento" NUMBER(10) NOT NULL,
  "Codigo" NVARCHAR2(30) NOT NULL,
  "Nome" NVARCHAR2(80) NOT NULL,
  PRIMARY KEY ("IdProcedimento")
)
CREATE SEQUENCE "Procedimento_SEQ"
CREATE OR REPLACE TRIGGER "Procedimento_INS_TRG"
  BEFORE INSERT ON "Procedimento"
  FOR EACH ROW
BEGIN
  SELECT "Procedimento_SEQ".NEXTVAL INTO :NEW."IdProcedimento" FROM DUAL;
END;
CREATE TABLE "GrupoProcedimento" ( 
  "IdGrupoProcedimento" NUMBER(10) NOT NULL,
  "Codigo" NVARCHAR2(15) NOT NULL,
  "Nome" NVARCHAR2(80) NOT NULL,
  PRIMARY KEY ("IdGrupoProcedimento")
)
CREATE SEQUENCE "GrupoProcedimento_SEQ"
CREATE OR REPLACE TRIGGER "GrupoProcedimento_INS_TRG"
  BEFORE INSERT ON "GrupoProcedimento"
  FOR EACH ROW
BEGIN
  SELECT "GrupoProcedimento_SEQ".NEXTVAL INTO :NEW."IdGrupoProcedimento" FROM DUAL;
END;
CREATE TABLE "ProcedimentoEspecialidades" ( 
  "IdProcedimento" NUMBER(10) NOT NULL,
  "IdEspecialidade" NUMBER(10) NOT NULL,
  PRIMARY KEY ("IdProcedimento", "IdEspecialidade")
)
CREATE INDEX "IX_IdProcedimento" ON "ProcedimentoEspecialidades" ("IdProcedimento")
CREATE INDEX "IX_IdEspecialidade" ON "ProcedimentoEspecialidades" ("IdEspecialidade")
CREATE TABLE "ProcedimentoGrupos" ( 
  "IdProcedimento" NUMBER(10) NOT NULL,
  "IdGrupoProcedimento" NUMBER(10) NOT NULL,
  PRIMARY KEY ("IdProcedimento", "IdGrupoProcedimento")
)
CREATE INDEX "IX_IdProcedimento" ON "ProcedimentoGrupos" ("IdProcedimento")
Devart.Data.Oracle.OracleException (0x80004005): ORA-00955: name is already used by an existing object

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Code-First Migrations: Index names problem

Post by Shalex » Wed 19 Mar 2014 11:43

Thank you for your report. We have reproduced the problem and are investigating it.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Code-First Migrations: Index names problem

Post by Shalex » Wed 19 Mar 2014 12:01

Sorry for the misleading message above. The problem was associated with existing objects in a test database. The test with a clean database does not reproduce the issue.

Could you please send us a small test project for reproducing the issue in our environment?

Post Reply