spatial_ref_sys and geometry_columns

Let’s say you have a little accident while messing with the schema of your PostGIS-enabled database, and the spatial_ref_sys and geometry_columns tables get wiped out. When you go to install a GeoDjango-enabled app such as the example “world” app, Python will yell at you, and you will be very sad:

It fails, because you accidentally dropped some very important PostGIS tables from the database. So you google a bit and find this: http://postgis.refractions.net/documentation/manual-1.5/ch02.html#id418654 which tells you what you need to do to set up a clean PostGIS installation.

So you dig around in the shared host, until you find where the PostGIS files are, and in particular spatial_ref_sys.sql:

So you try to run spatial_ref_sys.sql, and it fails, and you are sad:

Normally to create the missing table, you would run the postgis.sql script, and it would create these tables alongside the various GIS stored procedures. On a shared host, this probably won’t be possible, because you won’t have the permissions:

If you dig through postgis.sql for the proper CREATE TABLE statements, you’ll see something like:

You can pop these into a PostgreSQL admin shell and recreate these tables. Then you just have to rerun the spatial_ref_sys.sql file, and you should see:

Then, when you run the Django management script again, it should succeed.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.