0

Django Version 1.9.6. Python Version: 3.4.3

I've made a binary field in my model (flal_file = models.BinaryField()) for inserting binary data in the database.

Database column is blob field.

I get that error when creating an object (insert).

Commenting out flal_file prevents this error.

I don't know why I get this error, since this is a binary field.

Is that a bug with older versions of Django? Can anyone help me debug this issue?

enter image description here

myfile = request.FILES['uploaded_file'] 
b = DocFileAllocation.objects.using('db_test_').create(
                   flal_file=myfile.read(), #binary data
                   flal_id_no=seq_doc_file, 
                   bmeta_id_no=seq_metadata,
                   flal_file_subject=subject,
                   )

b.save(using='db_test_')
csandreas1
  • 2,026
  • 1
  • 26
  • 48
  • without knowing anything about Django it seems like Oracle is silently casting your binary data as a LONG datatype. Are you able to declare data types before you insert? If so declaring flal_file as a BLOB should do it – kevinskio Mar 10 '20 at 16:45
  • The question here is that it's already declared in Django model as a binary field but the error talks about LONG – csandreas1 Mar 10 '20 at 16:54
  • see here for same issue and a workaround https://stackoverflow.com/q/21197523/851930 – kevinskio Mar 10 '20 at 16:55
  • This error seems to happen with older versions of Django. But only on binaryfield – csandreas1 Mar 10 '20 at 17:00
  • What is your version of Django? – kevinskio Mar 10 '20 at 17:06
  • Django Version `1.9.6`. Python Version: `3.4.3` – csandreas1 Mar 10 '20 at 17:08
  • I read the file in Python and store it in a variable. I noticed when printing it, it starts with `b'`. When i insert a basic string it works without error. I use python `read()` method to read the uploaded file and send it to the database. Issue seems to lie there – csandreas1 Mar 11 '20 at 08:47

1 Answers1

0

Problem solved by adding the primary key via a database trigger. In the model it should be AutoField.

Also when saving the object specify the update_fields to avoid primary key issue.

csandreas1
  • 2,026
  • 1
  • 26
  • 48