GeoDjango with MySQL8

26 views
Skip to first unread message

Utkarsh Bansal

unread,
May 25, 2020, 11:06:26 AM5/25/20
to Django users
I am facing problems while trying to use GeoDjango (v2.2) with MySQL 8.0.19

I created a new PointField and ran makemigrations
geo_code = PointField(srid=4326)

On running sqlmigrate on the generated migration - I notice that the column does not have a SRID constrain
BEGIN;
--
-- Create model Location
--
CREATE TABLE `locations_location` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `geo_code` POINT NOT NULL);
CREATE SPATIAL INDEX `locations_location_geo_code_id` ON `locations_location`(`geo_code`);
COMMIT;

Now anything I add to the column is saved with SRID 0, which is incorrect.

Next, I tried creating the column with the correct SRID by using migrations.SeparateDatabaseAndState to generate the column.
ALTER TABLE backend_userprofile ADD COLUMN geocode_point POINT NULL SRID 4326;

Now if I try to insert data in this new column, I get and error because Django is still trying to insert with SRID 0 and MySQL does not allow that
django.db.utils.OperationalError: (3643, "The SRID of the geometry does not match the SRID of the column 'geo_code'. The SRID of the geometry is 0, but the SRID of the column is 4326. Consider changing the SRID of the geometry or the SRID property of the column.")

Is there a way to make Django use correct SRIDs with MySQL? I also found a ticket on the issue tracker which seems related https://code.djangoproject.com/ticket/27464



Tim Graham

unread,
May 25, 2020, 6:02:28 PM5/25/20
to Django users
Hi, you might have better luck getting an answer on the GeoDjango mailing list: https://groups.google.com/forum/#!forum/geodjango
Reply all
Reply to author
Forward
0 new messages