0
I have this chart
+---------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+---------------+------+-----+---------+-------+
| CNPJ | char(14) | NO | PRI | NULL | |
| fkusuario | int(11) | NO | MUL | NULL | |
| DataCadastro | date | YES | | NULL | |
| Razao | varchar(150) | YES | | NULL | |
| Operadora | varchar(100) | YES | | NULL | |
| Linhas | int(11) | YES | | NULL | |
| Classificacao | varchar(3) | YES | | NULL | |
| Vigencia | date | YES | | NULL | |
| mesesContrato | int(11) | NO | | NULL | |
| Fidelidade | varchar(50) | NO | | NULL | |
| ValorGasto | decimal(10,2) | YES | | NULL | |
| FixoEmpresa | varchar(17) | YES | | NULL | |
| Gestor | varchar(150) | YES | | NULL | |
| Celular | varchar(17) | YES | | NULL | |
| FixoGestor | varchar(17) | YES | | NULL | |
| Email | varchar(150) | YES | | NULL | |
| Obs | varchar(255) | YES | | NULL | |
+---------------+---------------+------+-----+---------+-------+
From it I created an identical view but without the field fkusuario
and I’m trying to make an insert in this view
insert into checagens_sem_fk values('8425787107104','2019-04-16', 'REDECARD S A', 'VIVO', '23', 'A', '2018-05-15', '12', 'Não Fidelizado B','850', '994901415', 'BRUNO', '15997677764', '1532594563', '[email protected]', 'teste');
But she makes a mistake:
Error Code: 1423. Field of view 'global.checagens_sem_fk' underlying table doesn’t have a default value
What could it be? can I do an Insert in a view? or is it on account of removing the foreign key.
EDIT with the creation of the view
+---------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+---------------+------+-----+---------+-------+
| CNPJ | char(14) | NO | | NULL | |
| DataCadastro | date | YES | | NULL | |
| Razao | varchar(150) | YES | | NULL | |
| Operadora | varchar(100) | YES | | NULL | |
| Linhas | int(11) | YES | | NULL | |
| Classificacao | varchar(3) | YES | | NULL | |
| Vigencia | date | YES | | NULL | |
| mesesContrato | int(11) | NO | | NULL | |
| Fidelidade | varchar(50) | NO | | NULL | |
| ValorGasto | decimal(10,2) | YES | | NULL | |
| FixoEmpresa | varchar(17) | YES | | NULL | |
| Gestor | varchar(150) | YES | | NULL | |
| Celular | varchar(17) | YES | | NULL | |
| FixoGestor | varchar(17) | YES | | NULL | |
| Email | varchar(150) | YES | | NULL | |
| Obs | varchar(255) | YES | | NULL | |
+---------------+---------------+------+-----+---------+-------+
You can put the view creation script in the question?
– vinibrsl
This error usually occurs when using a
insert
without column names and one of the uninformed columns does not have a default value defined.– Ronaldo Araújo Alves
@vnbrs I edited the question
– Patrick Perdigão
The view is just a projection of the table data it represents. When you enter an editable view actually the insertion is taking place in the table that gives rise to the view data and in your case there is a foreign key
fkusuario INT NOT NULL
that requires a value and that key not referenced by the view which will result in an error every time aINSERT
is done in the vision.– Augusto Vasques
@Augustovasques understood, I will have to look for another alternative so, thank you ^^
– Patrick Perdigão