[SOLVED] Error: SQLSTATE[42S22]: Column not found: 1054

Hi guys!

I create my system in PHP 5.6, but deploy it in PHP 7.0.

I’m getting Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘Aluno.id_auto_escola’ in ‘where clause’ when I try to get data in my hasOne query.

I’m very mess bacause this error appears in just one use case, in all other times the function works fine.

my call:
$aluno = TableRegistry::get(‘aluno’)
->getAlunos(
$idAutoEscola,
$idAluno,
‘S’
)[0];

my getAlunos method:
public function getAlunos($idAutoEscola, $idAluno = null, $isAtivo = null, $nomeCpf = null) {

    $aluno = $this->find('all', ['contain' => ['Parcelamento', 'Parcelamento.Parcelas', 'AutoEscola', 'Categori', 'TpProcesso', 'FmPagamento']])
                    ->where(['Aluno.id_auto_escola' => $idAutoEscola]);

    if(!empty($idAluno)) $aluno->where(['Aluno.id_aluno' => $idAluno]);
    if(!empty($isAtivo)) $aluno->where(['Aluno.is_ativo' => $isAtivo]);
    if(!empty($nomeCpf))
        $aluno->where(['OR' => [
                        'nome LIKE' => '%' . $nomeCpf . '%',
                        'cpf' => $nomeCpf
                    ]]);

    $aluno->order(['nome']);

    $aluno = $aluno->toList();

    foreach($aluno as $a) {
        $this->setStatusPagamento($a);
    }

    return $aluno;
}

What can I do solve this problem?

Thanks!

I’ve just find the problem!

Cake was generating the query
SELECT… FROM FROM aluno aluno


WHERE (Aluno.id_auto_escola = :c0
AND Aluno.id_aluno = :c1
AND Aluno.is_ativo = :c2)

The problem is that my production database wat setted to work with case sensitive table names. I just setup it to unsensite with ```
lower_case_table_names = 1


Reguards

Hi, I have the same problem. How can I change it on production server when I do not have access to ini file?