datamade / how-to

📚 Doing all sorts of things, the DataMade way
MIT License
86 stars 12 forks source link

Adjust default DATABASE_URL in new-django-app template when postgis is True #93

Closed jeancochrane closed 3 years ago

jeancochrane commented 4 years ago

Documentation request

When the postgis variable is set to True, the new-django-app Cookiecutter template will produce the wrong value for DATABASE_URL:

https://github.com/datamade/how-to/blob/d95e49a220feca259b98e3be44266f554f0b67d8/docker/templates/new-django-app/%7B%7Bcookiecutter.app_name%7D%7D/%7B%7Bcookiecutter.module_name%7D%7D/settings.py#L93

The database connection string should have the postgis: prefix, otherwise any migrations that use a GeoDjango field will fail with the following error:

AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'
jeancochrane commented 4 years ago

Also: We need to adjust ENGINE when PostGIS is set. See: https://github.com/datamade/california-dream-index/commit/6f040cc276eef98eb04150eabf2233cc582d6cdd

hancush commented 4 years ago

If you're using dj_database_url, you can pass the engine when you parse the database object from a connection string, e.g., https://github.com/datamade/la-metro-dashboard/blob/f296ea2b74d0c3cb02d89cbff578debb82e369b3/configs/connection_settings.py#L10-L16!

jeancochrane commented 4 years ago

That's a much better solution, thanks Hannah!