ActiveRecord :: StatementInvalid:期望PG :: InternalError"]"结束数据

时间:2015-06-15 07:29:07

标签: ruby postgresql activerecord

我是Ruby的新手并使用ActiveRecord。

我尝试使用ActiveRecord创建记录(即类的新实例)。我已经创建并运行了创建此文件的迁移:

class CreatePeople < ActiveRecord::Migration
    def change
        create_table :people do |t|
            t.string :first_name
            t.string :last_name
            t.datetime :birthdate
        end
    end
end

这是我的模型文件,其中包含一个名为Person的类:

class Person < ActiveRecord::Base
end

我去了终端并使用命令&#34; rake console启动了IRB控制台。&#34;我尝试了输入:person = Person.newperson = Person.create(first_name: "Dave", last_name: "Smith")。这两个输入只是给我这个错误信息:

ActiveRecord::StatementInvalid: PG::InternalError: ERROR: expected "]" to end datum, 
but got "0 0 0 0 ]}) :location 2634}}

ETA(完整错误消息):

ActiveRecord::StatementInvalid: PG::InternalError: ERROR: expected "]" to end datum, 
but got "0 0 0 0 ]}) :location 2634}} :targetList ({TARGETENTRY :expr {VAR 
:varno 4 :varattno 1 :vartype 19 :vartypmod -1 :varcollid 0 :varlevelsup 0 
:varnoold 4 :varoattno 1 :location 2224} :resno 1 :resname schemaname 
:ressortgroupref 0:resorigtbl 2615 :resorigcol 1: resjunk false} 
{TARGETENTRY :expr {VAR :varno 3 :varattno 1 :vartype 19 :vartypmod -1 
:varcollid 0 :varlevelsup 0 :varnoold 3: varattno 1 :location 2257} :resno 2 
:resname tablename :ressortgroupref 0 :resorigtbl 1259 :resorigcol 1 
:resjunk false} {TARGETENTRY :expr {FUNCEXPR :funcid 1645 :funcresulttype 19 
:funcretset false :funcvariadic false :funcformat 0: funccollid 0 
:inputcollid 0 :args ({VAR :varno 3: varattno 5 :vartype 26 :vartypmod -1 
:varcollid 0 :varlevelsup 0 :varnoold 3 : varoattno 5 :location 2305}) 
:location 2289} :resno 3 :resname tableowner :ressortgroupref 0 :resorigtble 
0 :resorigcol 0 :resjunk false} {TARGETENTRY :expr {VAR :varno 6 :varattno 1 
:vartype 19 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 6 : varattno 
1 :location 2340} :resno 4 :resname tablespace :ressortgroupref 0 
:resorigtble 1213 :resorigcol 1 :resjunk false} {TARGETENTRY :expr {VAR 
:varno 3 :varttno 13 :vartype 16 :vartypmod -1 :varcollid 0 :varlevelsup 0 
:varnoold 3 :varoattno 13 :location 2373} :resno 5 :resname hasindexes 
:ressortgroupref 0 :resorigtble 1259 :resorigcol 13 :resjunk false} 
{TARGETENTRY :expr {VAR :varno 3 :varattno 21 :vartype 16 :vartypmod -1 
:varcollid 0 :varlevelsup 0 :varnoold 3 :varoattno 21 :location 2410} :resno 
6 :resname hasrules :ressortgroupref 0 :resorigtble 1259 :resorigcol 21 
:resjunk false} {TARGETENTRY :expr {VAR :varno 3 :varattno 22 :vartype 16 
:vartypmod -1 :varcollid 0 :varlevels up 0 :varnoold 3 :varoattno 22 
:location 2445} :resno 7 :resnmae hastriggers :ressortgroupref 0 :resorigtbl 
1259 :resorigcol 22 :resjunk false}} :withCheckOptions <> :returningList <> 
:groupClause <> :havingQual <> :windowCaluse <> :distinctClause <> 
:sortClause <> :limitOffset <> :limitCount <> :rowMarks <> :setOperations <> 
:constraintDeps <>})”; length = 1

    LINE 2:     FROM pg_tables
    :     SELECT TABLENAME
          FROM pg_tables
          WHERE schemaname = ANY (current_schemas(false))
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/connection_adapters/postgresql/database_statements.rb:147:in ‘async_exec’
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/connection_adapters/postgresql/database_statements.rb:147:in ‘block in query’
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/connection_adapters/abstract_adapter.rb:473: in ‘block in log’
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activesupport-4.2.1/lib
/active_support/notifications/instrumenter.rb:20:in ‘instrument’
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/connection_adapters/abstract_adapter.rb:467:in ‘log’
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/connection_adapters/postgresql/database_statements.rb:146:in ‘query’
    From C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/connection_adapters/postgresql/schema_statements.rb:91:in ‘tables’
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/connection_adapters/schema_cache.rb:90:in ‘prepare_tables’
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/connection_adapters/schema_cache.rb:22:in ‘table_exists?’
    From C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/model_schema.rb:230:in ‘table_exists?’
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/attribute_methods/primary_key.rb:97: in ‘get_primary_key’
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/attribute_methods/primary_key.rb:95:in ‘reset_primary_key’
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/connection_adapters/postgresql/
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/attribute_methods/primary_key.rb:73:in ‘primary_key’
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/model_schema.rb:234:in ‘attributes_builder’
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/model_schema.rb:254: in ‘_default_attributes’
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/core.rb:273:in ‘initialize’
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/inheritance.rb:61:in ‘new’
    from C:/Ruby200/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record
/inheritance.rb:61:in ‘new’

1 个答案:

答案 0 :(得分:0)

正如m_x所述,PG设置存在问题。 ActiveRecord本身没有问题。为了解决这个特定的StatementInvalid Error,需要为PostgreSQL执行完全卸载和重新安装。

似乎PostgreSQL的数据文件夹在某种程度上被破坏了。只需使用控制面板或PostgreSQL卸载程序卸载,就无法完全卸载PostgreSQL。具体来说,PostgreSQL没有从注册表中卸载。这种部分卸载阻止了使用其中正确的bin和lib目录创建PostgreSQL的新数据文件夹。需要遵循这些步骤才能完全卸载PostgreSQL:

  1. 从控制面板或PostgreSQL卸载PostgreSQL 从PostgreSQL目录中卸载。
  2. 删除PostgreSQL目录文件夹
  3. 运行CCleaner以确保删除旧的PostgreSQL注册表项。 (可在此免费下载:http://www.filehippo.com/download_ccleaner
  4. 下载并重新安装PostgreSQL