Field 'Hash' doesn’t have a default value

Asked

Viewed 196 times

1

When I try to insert into a table this error appears Field 'Hash' doesn't have a default value

mysqli_query($conn, "SET SQL_MODE = ''; INSERT INTO ".SQL_TABELA."(`Chave`, `Nome`, `Categoria`, `Tamanho`, `Link`, `Hash`, `Tipo`, `Parceiro`) VALUES ('".$chave."', '".$name."', '".$category."', '".$size."', '".$link."', '".$hash."', '".$type."', '".$parceiro."')") or die(mysqli_error($conn));

Note: I tried to remove the SET SQL_MODE = '';

  • Have you tried creating a default value for the Hash? For example ALTER TABLE Tabela MODIFY COLUMN Hash VARCHAR(255) DEFAULT NULL;.

  • Solved, put this as an answer please.

2 answers

2


You need to set a default value for the Hash, for example:

ALTER TABLE Tabela MODIFY COLUMN Hash VARCHAR(255) DEFAULT NULL;

If you use NOT NULL use '' instead of NULL:

ALTER TABLE Tabela MODIFY COLUMN Hash VARCHAR(255) NOT NULL DEFAULT '';

This will set a default value for the column, when no value is specified it will be used. Note of adjusting the VARCHAR(255) for your need.

0

Try using the command

set @@global.sql_mode=''; 

This will disable Strict mode.

can also change through my.ini. search for sql-mode and delete what’s in quotes ""

If you change in my.ini you will need to restart your mysql

Browser other questions tagged

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