-1
I have a table in a DbContext
, change her name, update to database
and when I run I get redirected to Visual Studio with the following error message:
Invalid column name 'Setorid'.
Obs:The table name is Setor_id. I change the name on 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);