[英]How do I fix missing PostGIS SRIDs in PostgreSQL?
I received the following error while running my Rspec test suite: 运行我的Rspec测试套件时收到以下错误:
PG::InternalError: ERROR: GetProj4StringSPI: Cannot find SRID (4326) in spatial_ref_sys
I know that I enabled the PostGIS extension. 我知道我启用了PostGIS扩展。 How do I fix this?
我该如何解决?
The problem is that something removed the rows from the spatial_ref_sys
table. 问题是有些东西从
spatial_ref_sys
表中删除了行。
In my case, the problem was in my DatabaseCleaner
configuration in my spec_helper.rb
. 就我而言,问题出在我的
spec_helper.rb
DatabaseCleaner
配置中。 It was configured to delete/truncate the table. 它被配置为删除/截断表。
To prevent that behavior, change the configuration. 要防止该行为,请更改配置。 For me, that was:
对我来说,那是:
config.before(:suite) do
DatabaseCleaner.strategy = :deletion, {:except => %w[spatial_ref_sys]}
DatabaseCleaner.clean_with :truncation, {:except => %w[spatial_ref_sys]}
end
Now you'll need to regenerate the rows in that table. 现在,您需要重新生成该表中的行。 Use the script named
spatial_ref_sys.sql
to do that. 使用名为
spatial_ref_sys.sql
的脚本来执行此操作。
I use Postgres.app, so the command to run that script was: 我使用Postgres.app,所以运行该脚本的命令是:
/Applications/Postgres.app/Contents/MacOS/bin/psql -d database_name -f /Applications/Postgres.app/Contents/MacOS/share/contrib/postgis-2.0/spatial_ref_sys.sql
Your command may be slightly different. 您的命令可能略有不同。
Running rake db:test:prepare
should restore the values in spatial_ref_sys
. 运行
rake db:test:prepare
应该恢复spatial_ref_sys
的值。
UPDATE: This is fixed in version 1.4.1: https://github.com/DatabaseCleaner/database_cleaner/pull/328 更新:这在版本1.4.1中得到修复: https : //github.com/DatabaseCleaner/database_cleaner/pull/328
There is a bug in database_cleaner
version 1.4.0, so you need to specify the schema of the table exceptions: database_cleaner
1.4.0版中存在一个错误,因此您需要指定表异常的模式:
DatabaseCleaner.strategy = :truncation, { except: ["public.spatial_ref_sys"] }
DatabaseCleaner.clean_with :truncation, { except: ["public.spatial_ref_sys"] }
In version 1.4.0, the schema is returned as part of the table name. 在1.4.0版中,架构作为表名的一部分返回。 See https://github.com/DatabaseCleaner/database_cleaner/pull/282
请参阅https://github.com/DatabaseCleaner/database_cleaner/pull/282
This is due to not having a spatial_ref_sys
table. 这是因为没有
spatial_ref_sys
表。 Insert this table using the following: 使用以下内容插入此表:
psql -d country -f /usr/share/postgresql/9.3/contrib/postgis-2.1/spatial_ref_sys.
country
is the database name, and /usr/share/.../spatial_ref_sys.sql
is the path where my file is stored. country
是数据库名称,而/usr/share/.../spatial_ref_sys.sql
是存储文件的路径。 This works for me. 这适合我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.