Hello Thank for your reply, but I am sorry, I am afraid I did not understand well your observation.
My first worry is the type of my column ‘location’
As I added in my models
location = PointField(blank=True, null=True, srid=4326)
I supposed my column should a tyope of POINT and not GEOMETRY, isn’t?
After the initial migration files, they start to depend on previous migration files. If you don’t run one of them, you may not end up with a database in the same state.
Now regarding your comments, as I add the above line, the database schema should be changed after I launched makemigrations
? and migrate
should push the change to the DB?
Or should I “manually” change the schema file. In my lately App, I created a column column and I updated my models.py and it was fine. But now, I am curious to understand that mechanic.
I am double confuse, because I just ran ./manage.py inspectdb
and it returned me this line
location = models.GeometryField(blank=True, null=True)
To clarify the objectif of ‘location’, I have the latitude saved into the column ‘station_lat’ and the longitude saved into the column ‘station_lng’. As far as I remember, my App or Django could not read the both column and I needed to create a column ‘location’ in order to have the latitude and the longitude in the same column and separeted by a coma.
The save() helped my to copy the lat and lng to the location
class Stations(models.Model):
id_station = models.AutoField(primary_key=True)
fields_id_field = models.ForeignKey(Fields, models.DO_NOTHING, db_column='fields_id_field')
stations_types_id_stations_type = models.IntegerField()
station_name = models.CharField(max_length=20)
station_longname = models.CharField(max_length=45, blank=True, null=True)
station_active = models.BooleanField()
station_archive = models.BooleanField()
location = PointField(blank=True, null=True, srid=4326)
station_lat = models.FloatField(blank=True, null=True)
station_lng = models.FloatField(blank=True, null=True)
station_alt = models.DecimalField(max_digits=6, decimal_places=2, blank=True, null=True)
installed = models.DateTimeField()
station_description = models.TextField(blank=True, null=True)
ttn_app_id = models.CharField(max_length=20)
ttn_dev_id = models.CharField(max_length=20)
ttn_hardware_serial = models.CharField(max_length=20)
station_created = models.DateTimeField()
station_order = models.IntegerField()
map = models.BooleanField()
class Meta:
managed = False
db_table = 'stations'
def save(self, *args, **kwargs):
self.location = Point(float(self.station_lng), float(self.station_lat))
super(Stations, self).save(*args, **kwargs)
As the aboce code worked before, I would like to keep it, but I have some doubt about the column type of my DB (POINT, GEOMETRY, other)