Error Code: 1048, SQL State: 23000 Column 'colegiado_id' can not be null

0

Hello, this error

"[Error Code: 1048, SQL State: 23000]  Column 'colegiado_id' cannot be null"

It happens when I try to run the SQL command below directly in MySQL:

start transaction;
INSERT INTO EspecialistasColegiados (colegiado_id, especialista_id) (
    select
        col.id as colegiado_id,
        esp.id as especialista_id

    from Especialista esp
        inner join importacao imp ON imp.idimportacao = esp.id
        left join Colegiado col ON col.nome like concat('%',imp.CURSOS,'%')
    );
rollback;
    
asked by anonymous 04.03.2015 / 22:06

1 answer

1

The column "colegiado_id" can not be null. You have two alternatives:

perform an alter table in the Collegiate Specialists table to accept null value or change the query (select) to not return null values

Alter in table

ALTER TABLE 'MyTable' ALTER COLUMN 'MinhaColuna' INT DEFAULT NULL;

Modify select

 start transaction;
 INSERT INTO EspecialistasColegiados (colegiado_id, especialista_id) (
select
    col.id as colegiado_id,
    esp.id as especialista_id

from Especialista esp
    inner join importacao imp ON imp.idimportacao = esp.id
    left join Colegiado col ON col.nome like concat('%',imp.CURSOS,'%')
where colegiado_id IS NOT NULL
 );
rollback;
    
04.03.2015 / 22:20