1
resposta

php artisan test

Está aparecendo erro em um arquivo:

Tests\Feature\SeriesRepositoryTest
  ⨯ when a series is created its seasons and episodes must also be created

  ---

  • Tests\Feature\SeriesRepositoryTest > when a series is created its seasons and episodes must also be created
   Illuminate\Database\QueryException 

  SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: series.nome (SQL: insert into "series" ("updated_at", "created_at") values (2023-12-02 22:57:36, 2023-12-02 22:57:36))

  at F:\....\vendor\laravel\framework\src\Illuminate\Database\Connection.php:760
    756▕         // If an exception occurs when attempting to run a query, we'll format the error
    757▕         // message to include the bindings with SQL, which will make this exception a
    758▕         // lot more helpful to the developer instead of just the database's errors.
    759▕         catch (Exception $e) {
  ➜ 760▕             throw new QueryException(
    761▕                 $query, $this->prepareBindings($bindings), $e
    762▕             );
    763▕         }
    764▕     }

  1   F:\....\vendor\laravel\framework\src\Illuminate\Database\Connection.php:545
      PDOException::("SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: series.nome")

  2   F:\....\vendor\laravel\framework\src\Illuminate\Database\Connection.php:545
      PDOStatement::execute()
protected function runQueryCallback($query, $bindings, Closure $callback)
    {
        // To execute the statement, we'll simply call the callback, which will actually
        // run the SQL against the PDO connection. Then we can calculate the time it
        // took to execute and log the query SQL, bindings and time in our memory.
        try {
            return $callback($query, $bindings);
        }

        // If an exception occurs when attempting to run a query, we'll format the error
        // message to include the bindings with SQL, which will make this exception a
        // lot more helpful to the developer instead of just the database's errors.
        catch (Exception $e) {
            throw new QueryException(
                $query, $this->prepareBindings($bindings), $e
            );
        }
    }
1 resposta

Eita! Parece que tá rolando um problema na criação de uma série, hein? O erro tá dando um toque sobre uma violação de restrição de integridade no banco de dados. Olhando o código, parece que tá rolando um insert na tabela "series", mas tá faltando informação pro campo "nome". Ele tá mandando só as datas de atualização e criação. Mano, dá uma revisada na lógica de criação das séries, certeza que tá faltando algo aí.

O trecho de código que tá dando o erro mostra a tentativa de execução do SQL e, quando dá ruim, ele pula pro bloco de catch, lançando essa exceção de QueryException. Ou seja, alguma coisa tá errada na hora de inserir no banco.

Dá uma conferida na função runQueryCallback, especialmente na parte onde tá rolando o insert. Pode ser que o nome da série não esteja sendo passado corretamente ou algo do tipo.

Boa sorte aí! Se precisar de mais detalhes ou ajuda, manda ver.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software