Django, ошибка `(1054, "Unknown column 'aicrpagrometdaily.station_info_state_dist_code' in 'on clause'")` on join query

models.py

class AicrpAgroMetStationInfo(models.Model):
STATION_NAME = models.CharField(max_length=255)
STATE = models.CharField(max_length=255)
STATE_DIST_CODE = models.CharField(max_length=255, unique=True, db_column='state_dist_code')
WMO_ID = models.FloatField()
LATITUDE = models.FloatField()
LONGITUDE = models.FloatField()
ALTITUDE = models.FloatField()
SOILTYPE = models.CharField(max_length=255)
AWHC = models.CharField(max_length=255)
AESR = models.CharField(max_length=255)
NATP_ZONE = models.CharField(max_length=255)

    class Meta:
        managed = True
        db_table = "aicrpagrometstation_info"
    
    def __str__(self):
        return self.STATION_NAME

class AicrpAgroMetDaily(models.Model):
WMO_ID = models.FloatField()
STATE_DIST_CODE = models.CharField(max_length=255, db_column='state_dist_code_daily')
station_info = models.ForeignKey(
AicrpAgroMetStationInfo,
to_field='STATE_DIST_CODE',
db_column='station_info_state_dist_code',  # Ensure a distinct column name
on_delete=models.CASCADE,
)
DATE1 = models.CharField(max_length=50)
MAXT = models.CharField(max_length=50)
MINT = models.CharField(max_length=50)
RH1 = models.CharField(max_length=50)
RH2 = models.CharField(max_length=50)
WS = models.CharField(max_length=50)
RF = models.CharField(max_length=50)
SSH = models.CharField(max_length=50)
EVP = models.CharField(max_length=50)

    class Meta:
        managed = True
        db_table = "aicrpagrometdaily"
    
    def __str__(self):
        return self.DATE1

views.py

def get_agromet_data(request):
try:
data = AicrpAgroMetDaily.objects.select_related('station_info').values(
'station_info__STATE', 'station_info__STATION_NAME', 'station_info__SOILTYPE',
'station_info__LATITUDE', 'station_info__LONGITUDE', 'station_info__ALTITUDE',
'DATE1', 'MAXT', 'MINT', 'RH1', 'RH2', 'WS', 'RF', 'SSH', 'EVP'
)

        data_list = list(data)  # Convert QuerySet to list for easier manipulation
        return JsonResponse(data_list, safe=False)
    except Exception as e:
        return JsonResponse({'error': str(e)}, status=500)

Я пытаюсь создать api из 2 таблиц данных в djnago, но возникает ошибка мой sql запрос SELECT ai.STATE, ai.STATION_NAME, ai.SOILTYPE, ai.LATITUDE, ai.LONGITUDE, ai.ALTITUDE, ad.DATE1, ad.MAXT, ad.MINT, ad.RH1, ad.RH2, ad.WS, ad.RF, ad.SSH, ad.EVP from aicrpagrometstation_info ai join aicrpagrometdaily ad on ai.STATE_DIST_CODE = ad.STATE_DIST_CODE; your text я ожидаю в 0 { State Station Soil Type Latitude Longitude Altitude Date Max Temp. Мин. темп. RH1 RH2 RF WS SSH EVP } в таком формате

Вернуться на верх