You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently tried to add a fingerprint field to a model and then perform a migration. Following the documentation, which suggests
class django_rdkit.models.BfpField(**options)
A bit vector fingerprint. It may be assigned using an ExplicitBitVect instance or with an update query using one of the implemented fingerprint functions.
I attempted to set a default using an instance of ExplicitBitVect like so:
to which Django's makemigrations complains that ExplicitBitVect is unserializable. Since it is initializable with an unsigned integer which Django can serialize just fine, I derived the class and decorated it (see Django Docs Migration Serializing):
This allows the class to be serialized and makemigrations passes, but migrate fails due to:
django.db.utils.ProgrammingError: column "morganbv_fp" is of type bfp but default expression is of type bytea
The SQL expression generated by makemigrations is:
BEGIN;
---- Add field morganbv_fp to compound--ALTERTABLE"rest_compound" ADD COLUMN "morganbv_fp" bfp DEFAULT '\000'::byteaNOT NULL;
ALTERTABLE"rest_compound" ALTER COLUMN "morganbv_fp" DROP DEFAULT;
COMMIT;
Which is of course nonsense. Now I don't know where exactly this would be corrected, but I suspect it's due to models/fields.py:
[...]
classBfpField(Field):
[...]
defget_prep_value(self, value):
# convert the ExplicitBitVect instance to the value used by the # db driverifisinstance(value, ExplicitBitVect):
value=six.memoryview(DataStructs.BitVectToBinaryText(value))
returnvalue
[...]
I fixed it by just setting the field to be nullable and the default null. It doesn't really matter whether I fill it with a nonsensical sfp instance or just allow it to be null in practice to me.
Is there a better way I completely missed? Otherwise I would recommend adapting the documentation to suggest allowing the fingerprint fields to be null in order for migrations to work.
Cheers and thanks for your time!
The text was updated successfully, but these errors were encountered:
I recently tried to add a fingerprint field to a model and then perform a migration. Following the documentation, which suggests
I attempted to set a default using an instance of
ExplicitBitVect
like so:to which Django's
makemigrations
complains thatExplicitBitVect
is unserializable. Since it is initializable with an unsigned integer which Django can serialize just fine, I derived the class and decorated it (see Django Docs Migration Serializing):This allows the class to be serialized and
makemigrations
passes, butmigrate
fails due to:django.db.utils.ProgrammingError: column "morganbv_fp" is of type bfp but default expression is of type bytea
The SQL expression generated by
makemigrations
is:Which is of course nonsense. Now I don't know where exactly this would be corrected, but I suspect it's due to models/fields.py:
I fixed it by just setting the field to be nullable and the default null. It doesn't really matter whether I fill it with a nonsensical sfp instance or just allow it to be null in practice to me.
Is there a better way I completely missed? Otherwise I would recommend adapting the documentation to suggest allowing the fingerprint fields to be null in order for migrations to work.
Cheers and thanks for your time!
The text was updated successfully, but these errors were encountered: