Mysqlexception . NET Core 2.1: Unknown column 'xxxx' in 'field list'

Asked

Viewed 304 times

0

I have a bizarre mistake I’d like to share with you.

I’m using Visual Studio 2017 and creating an MVC application with NET Core 2.1, based on a Mysql database and tables that already existed before.

I created a model called Result and created the Annotations to link correctly with the table and database. However, after creating the class, I decided to rename the columns in the table. Obviously, I also changed the Annotations to correctly reflect the changes.

However, when I am going to do some query to this table, the application returns error saying that the column xxxxxx (and there it shows the old name of the column) does not exist in the table, but I changed its name in the database and changed it in the class, however, the recompilation is not reflecting this change.

To clarify, I’m going to leave the code of the class below:


[Table("ProvasResultados")]
public class Resultado
{

    public Resultado() { }

    [Key]
    [Column("Ano")]
    public int Ano { get; set; }

    [Key]
    [Column("Prova")]
    public int ProvaId { get; set; }

    [Key]
    [Column("Atleta")]
    public int AtletaId { get; set; }

    [Key]
    [Column("Grupo")]
    public int GrupoId { get; set; }

    [Key]
    [Column("Atividade")]
    public int AtividadeId { get; set; }

    [Key]
    [Column("Tentativa")]
    public byte Tentativa { get; set; }

    [Column("Tempo")]
    public Nullable<System.TimeSpan> TempoRegistrado { get; set; }

    [Column("Indice")]
    public Nullable<decimal> IndiceRegistrado { get; set; }

    [Column("Pontuacao")]
    public Nullable<bool> Pontuacao { get; set; }

    [Column("MelhorDoDia")]
    public Nullable<bool> MelhorDoDia { get; set; }

    [Column("MelhorDoAno")]
    public Nullable<bool> MelhorDoAno { get; set; }

    [Column("RecordePessoal")]
    public Nullable<bool> RecordePessoal { get; set; }

    [ForeignKey("Ano, GrupoId, AtividadeId")]
    public AtividadePorGrupo GrupoAtividade { get; set; }

    [ForeignKey("Ano, ProvaId")]
    public Prova Prova { get; set; }

    [ForeignKey("Ano, ProvaId, AtletaId")]
    public Inscricao Inscricao { get; set; }
}

However, when MVC will "mount the select" to recover table data, I noticed in the error panel that select is as below


SELECT p.Ano, p.Prova, p.Atleta, p.Grupo, p.Atividade, p.Tentativa, p.IndiceAno, p.IndiceId, p.Indice, p.MelhorDoAno, p.MelhorDoDia, p.Pontuacao, p.RecordePessoal, p.Tempo
FROM ProvasResultados AS p
WHERE (p.Ano = @__Ano_0) AND (p.Prova = @__Prova_1)

And the mistake:

Mysql.Data.Mysqlclient.Mysqlexception (0x80004005): Unknown column p.Indiceano 'in field list

Where the "Best" column is now the old "Best" column. That is, the MVC is not reflecting the changes in the class I am determining.


Remembering it’s the first time I’ve dealt with. NET Core 2.1, so I’m picking up a bit, I wonder if anyone can help me with this problem.

Thanks for your help

  • I edited the description to better detail the error. I inserted the codes and the error that is happening.

  • Update. Looking at the class and the SELECT that is being mounted for the MVC, I just identified that the columns p.Indiceano and p.Indiceid are "ghosts" (rs), that is, they were not to be there, they were not configured, they do not exist in the table. How did they get there? I think that there is even clearer the help I need.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.