2

I looked at previous questions with the same problem but they all seem to be due to custom queries built by the person. However my problem is with django giving me this error. In my model I have 2 decimal fields for storing Longitude and Latitude

class TBuildings(models.Model):
    ixBuilding = models.AutoField(primary_key=True)
    ixLocation = models.ForeignKey(TLocations, verbose_name="Location")
    iBuildingNum = models.IntegerField(verbose_name="Building #")
    decLatitude = models.DecimalField(max_digits=9, decimal_places=6, verbose_name="Latitude", default=Decimal('0.0000'))
    decLongitude = models.DecimalField(max_digits=9, decimal_places=6, verbose_name="Longitude", default=Decimal('0.0000'))

    class Meta:
        db_table = "tBuildings"
        verbose_name = "Building"
        verbose_name_plural = "Buildings"
    def __str__(self):
        return "%s" % (self.iBuildingNum)

This model is added to my admin site where I create the Building object. But whenever I enter longitude and latitude (56.678,-12.26520) it gives me this error. I don't know why it's even trying to convert to text when I've told it to be a decimal

DatabaseError at /admin/ums/tbuildings/add/
(-2147352567, 'Exception occurred.', (0, u'Microsoft OLE DB Provider for SQL Server', u'Operand type clash: ntext is incompatible with decimal', None, 0, -2147217913), None)
Command:
SET NOCOUNT ON;DECLARE @sqlserver_ado_return_id table ([ixBuilding] int);INSERT INTO [tBuildings] ([ixLocation_id], [iBuildingNum], [decLatitude], [decLongitude]) OUTPUT INSERTED.[ixBuilding] INTO @sqlserver_ado_return_id VALUES (?, ?, ?, ?);SELECT * FROM @sqlserver_ado_return_id
Parameters:
[Name: p0, Dir.: Input, Type: adInteger, Size: -1, Value: "1", Precision: 0, NumericScale: 0, Name: p1, Dir.: Input, Type: adInteger, Size: -1, Value: "4096", Precision: 0, NumericScale: 0, Name: p2, Dir.: Input, Type: adBSTR, Size: -1, Value: "42.91899", Precision: 0, NumericScale: 0, Name: p3, Dir.: Input, Type: adBSTR, Size: -1, Value: "-81.26520", Precision: 0, NumericScale: 0]
john
  • 3,949
  • 7
  • 34
  • 56

0 Answers0