I have a table in a DbContext
, I change its name, I update the database
and when I run I am redirected to Visual Studio with the following error message:
Invalid column name 'SetorId'.
Note: The table name is Set_Id. I change the name in model
and in the table itself before updating the database
.
Model:
public class RamalModel
{
public int ID { get; set; }
[Required(ErrorMessage = "O nome é obrigatório.")]
public string Nome { get; set; }
[Required(ErrorMessage = "O número é obrigatório.")]
public int Numero { get; set; }
[ForeignKey("Setor")]
public int SetorId { get; set; }
public Setor Setor { get; set; }
}
DbContext:
public class RamaDb : DbContext
{
public DbSet<Usuario> Usuarios { get; set; }
public DbSet<RamalModel> Ramais { get; set; }
public DbSet<Setor> Setores { get; set; }
public DbSet<Area> Areas { get; set; }
}
Table:
CREATE TABLE [dbo].[RamalModels] (
[ID] INT IDENTITY (1, 1) NOT NULL,
[Nome] NVARCHAR (MAX) NOT NULL,
[Numero] INT NOT NULL,
[Setor_Id] INT DEFAULT ((0)) NOT NULL,
CONSTRAINT [PK_dbo.RamalModels] PRIMARY KEY CLUSTERED ([ID] ASC)
);
GO
CREATE NONCLUSTERED INDEX [IX_SetorId]
ON [dbo].[RamalModels]([Setor_Id] ASC);