ProgrammingError: column "X" has double precision of type, but expression is of type numeric []

I am trying to program an API with the Django Rest Framework and the Psycopg2 library. This API works with a PostgreSQL database. I need to save 2 fields of the float array in this db, because the API works with two sensors that transmit data to the Android application, and they are stored in APP in two arrays, and they are sent by JSON to the REST API.

These are my models.py, serializers.py and views_api.py:

Models.py

class DataTest(models.Model): patient = models.ForeignKey(Patient) label = models.CharField(max_length=36) angle_data = ArrayField(models.FloatField()) emg_data = ArrayField(models.FloatField()) created_at = models.DateTimeField(auto_now_add=True) modified_at = models.DateTimeField(auto_now=True) def __unicode__(self): return self.patient 

Serializers.py

 class DataTestSerializer(serializers.Serializer): pk = serializers.IntegerField(read_only=True) label = serializers.CharField() angle_data = serializers.ListField(child=serializers.FloatField()) emg_data = serializers.ListField(child=serializers.FloatField()) patient = serializers.PrimaryKeyRelatedField(queryset=Patient.objects.all()) def create(self, validated_data): return DataTest.objects.create(**validated_data) def update(self, instance, validated_data): instance.label = validated_data.get('label', instance.label) instance.angle_data = validated_data.get('angle_data', instance.angle_data) instance.emg_data = validated_data.get('emg_data', instance.emg_data) instance.patient = validated_data.get('patient', instance.patient) instance.save() return instance 

api.py

 class DataTestList(APIView): def get(self, request, format=None): dataTests = DataTest.objects.all() serializer = DataTestSerializer(dataTests, many=True) return Response(serializer.data) def post(self, request, format=None): serializer = DataTestSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.error_messages, status=status.HTTP_400_BAD_REQUEST) 

Finally, I tested the API and I sent an example JSON: {"Label": "Test", "angle_data": [1.434, 2.243, 3.234], "emg_data": [2.3, 2.1], "Patient": 1}

and I get the following error:

ProgrammingError: column "angle_data" has double type precision, but the expression is of type numeric [] LINE 1: ..., "created_at", "modified_at") VALUES (1, 'Test', ARRAY [1.0, ... ^

TIP: You will need to rewrite or apply the expression.

I was debugging the API and I saw that the serializer was getting a floating point list. I believe the problem is that the column in PostgreSQL is double precision and the floating point list is not double precision encoded.

Can someone help me?

Congratulations and thanks!

+6
source share

All Articles