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 =
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):
>
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
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
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
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
6 matches
Mail list logo