1

I am trying to insert an image into a MySQL database however I keep receiving this error;Error Code: 1048.

Column 'image' cannot be null. This is the code I am using.

 create table test_img (
              id int(10)  not null AUTO_INCREMENT PRIMARY KEY,
              name varchar(25) not null default '',
              image blob not null        
  )

 INSERT INTO test_img(ID,IMAGE) VALUES(1,LOAD_FILE ('C:\\human_centered_design_infographic.jpg'));

1 Answers1

0

From the MySQL manual:

LOAD_FILE(file_name)

Reads the file and returns the file contents as a string. To use this function, the file must be located on the server host, you must specify the full path name to the file, and you must have the FILE privilege. The file must be readable by all and its size less than max_allowed_packet bytes. If the secure_file_priv system variable is set to a nonempty directory name, the file to be loaded must be located in that directory.

If the file does not exist or cannot be read because one of the preceding conditions is not satisfied, the function returns NULL.

You probably get the NULL error because one of those conditions mentioned is applicable.

It's not readable by all or the server does not have the file privilege enabled or the file is larger than max_allowed_packet bytes.

Community
  • 1
  • 1
Erik
  • 74
  • 6