Postgres类型"{field type}"只是一个壳 [英] Postgres type "{field type}" is only a shell

查看:56
本文介绍了Postgres类型"{field type}"只是一个壳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Django&Postgres.我的迁移包含以下内容:

I use Django & postgres. My migration contains something like this :

db.create_table('location_locationlevel', (
        ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
        ('name_0', self.gf('django.db.models.fields.CharField')(max_length=75, null=True, blank=True)),
        ('name_1', self.gf('django.db.models.fields.CharField')(max_length=75, null=True, blank=True)),
        ('name_2', self.gf('django.db.models.fields.CharField')(max_length=75, null=True, blank=True)),
        ('name_3', self.gf('django.db.models.fields.CharField')(max_length=75, null=True, blank=True)),
        ('name_4', self.gf('django.db.models.fields.CharField')(max_length=100, null=True, blank=True)),
        ('geom', self.gf('django.contrib.gis.db.models.fields.MultiPolygonField')()),
    ))

运行迁移时,出现如下错误:

When I run migration, I get error like below:

django.db.utils.DatabaseError: type "geometry" is only a shell
LINE 1: ...ABLE public.location_locationlevel ADD COLUMN geom geometry 
                                                         ^
QUERY:  ALTER TABLE public.location_locationlevel ADD COLUMN geom geometry 
CONTEXT:  PL/pgSQL function addgeometrycolumn(character varying,character varying,character varying,character varying,integer,character varying,integer)

以前有没有人经历过类似的事情,解决方案是什么?

Did anyone have experienced something like this before, and what was the solution?

推荐答案

简而言之,您需要重新安装Postgis,可能只是 drop extension postgis; create extension postgis; .

In short, you need to reinstall postgis, possibly just drop extension postgis; and create extension postgis;.

您可能会丢失这种类型,但我怀疑只是这样,如果您想尝试的话,这里是2.3版本:

You could possibly be missing just this type, but I doubt it is just that, tho if you want to try, here is from 2.3:

CREATE TYPE public.geometry
   (INPUT=geometry_in,
       OUTPUT=geometry_out,
       RECEIVE=geometry_recv,
       SEND=geometry_send,
       TYPMOD_IN=geometry_typmod_in,
       TYPMOD_OUT=geometry_typmod_out,
       ANALYZE=geometry_analyze,
       CATEGORY='U', DEFAULT='',
       INTERNALLENGTH=-1, ALIGNMENT=double, STORAGE=MAIN);
ALTER TYPE public.geometry
  OWNER TO postgres;
COMMENT ON TYPE public.geometry
  IS 'postgis type: Planar spatial data type.';

关于什么外壳,可以在文档中了解更多有关它们的信息..

As for what shells, you can read more about them in documentation.

简而言之:某些类型需要一些函数,这些函数又需要声明with,因此通常都无法创建.

In short: Some types require functions that in turn require that type with is to be declared, so neither can be created - normally.

为了解决该问题,Postgres将创建外壳类型,这些外壳类型几乎是占位符,只是为了满足验证要求.

In order to workaround that problem, Postgres will create shell types that are pretty much placeholder just to satisfy validation.

在您的情况下, geometry 是外壳类型且未正确声明,这意味着postgis的安装不正确.

In your case geometry is shell type and was not properly declared, with means that postgis was not installed correctly.

Shell类型如下:

Shell type looks like this:

CREATE TYPE public.geometry
   (INPUT=shell_in,
       OUTPUT=shell_out,
       RECEIVE=-,
       SEND=-,
       ANALYZE=-,
       CATEGORY='P',
    PASSEDBYVALUE, DEFAULT='',
       INTERNALLENGTH=4, ALIGNMENT=int4, STORAGE=PLAIN);
ALTER TYPE public.geometry
  OWNER TO postgres;

需要外壳类型的函数可能是:

And function requiring shell type could be:

CREATE OR REPLACE FUNCTION geometry_in(cstring)
    RETURNS geometry
    AS '$libdir/postgis-2.3','LWGEOM_in'
    LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE;

如果回顾正确的 geometry 定义,您会注意到此函数是其中的一部分,但不在此Shell中.

If you look back at proper geometry definition you will notice that this function is part of it, but not in this shell.

这篇关于Postgres类型"{field type}"只是一个壳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆