Re: How to create a fixed-length binary field with a unique constraint?

2019-03-20 Thread Anubhav Gupta
Hi, My use case is exactly similar to this with one additional condition that I want this column to serve as Primary Key of my table. Now when I use the following code: class BinaryTable(models.Model): binary_hash = models.BinaryField(primary_key=True) comments =

Re: How to create a fixed-length binary field with a unique constraint?

2017-07-13 Thread winkelmann
On Thursday, July 13, 2017 at 4:06:38 PM UTC+2, Tom Evans wrote: [...] > Guido: > > You can make your own custom database types quite simply (completely > untested): > > class FixedSizedBinaryField(models.BinaryField): > def __init__(self, num_bytes=None, *args, **kwargs): >

Re: How to create a fixed-length binary field with a unique constraint?

2017-07-13 Thread 'Tom Evans' via Django users
On Tue, Jul 11, 2017 at 12:05 AM, Mike Morris wrote: > From your description (save a SHA-256 checksum), you do not need a binary > field. Binaries are always of indeterminant length; they can hold photos, > executables, sound files, etc. > > By definition, a SHA -256 is 256

Re: How to create a fixed-length binary field with a unique constraint?

2017-07-11 Thread ecas
I would use: fingerprint_sha256 = models.CharField(max_length=64, unique=True, db_index=True) In hexadecimal, a SHA-256 uses 64 characters (4 bits per char). The ASCII of the characters used in the hexadecimal representation are 1 byte in UTF-8 (0-9, a-f). -- You received this message

Re: How to create a fixed-length binary field with a unique constraint?

2017-07-10 Thread Mike Morris
From your description (save a SHA-256 checksum), you do not need a binary field. Binaries are always of indeterminant length; they can hold photos, executables, sound files, etc. By definition, a SHA -256 is 256 bytes of ASCII. You probably want a CharField(length=256). On 07/10/2017

How to create a fixed-length binary field with a unique constraint?

2017-07-10 Thread Guido Winkelmann - Hornetsecurity
Hi, How can I create a table with a fixed-length binary field with a unique constraint? I need to save a SHA-256 checksum as a part of my objects, and I need to make sure I never have two or more objects with the same checksum in the database. Also, I need to be able to look up objects by that