I am trying to insert a txt file into mysql table but it is not working. I have tried using LOAD_FILE but it gave me an error code – MySQLdb.IntegrityError: (1048, "Column ‘transcript’ cannot be null")
cursor.execute("insert into `movies` (`movie_name`,`movie_file`,`movie_password`,`transcript`) values (%s,%s,%s, LOAD_FILE('/APPLES/transcription.txt'))",[moviename,moviefile,password])
I keep getting an Integrity Error
MySQLdb.IntegrityError: (1048, "Column ‘transcript’ cannot be null")
Could someone please help me in inserting a file into sql table. Thank you in advance
2
Answers
The error you’re encountering with
LOAD_FILE()
in MySQL usually occurs when the file is not accessible by MySQL due to reasons like the file not being on the MySQL server, permissions issues, or restrictions set by MySQL’ssecure-file-priv
option. To address this, ensure the file exists on the MySQL server with the correct permissions and is within a directory allowed bysecure-file-priv
. Alternatively, you can bypass these limitations by reading the file content in your Python code and inserting it directly into the database:There could be a problem with file permissions, check that.
otherwise, you can try to read it using python and then insert the data directly into SQL.