psql未定义表,关系不存在

时间:2014-08-31 01:34:53

标签: ruby-on-rails ruby-on-rails-3 postgresql activerecord rails-activerecord

/Users/0okyleo0/.gem/ruby/2.1.2/gems/activerecord-4.1.2/lib/active_record/connection_adapters/postgresql_adapter.rb:822:in `async_exec': PG::UndefinedTable: ERROR:  relation "events" does not exist (ActiveRecord::StatementInvalid)
LINE 5:                WHERE a.attrelid = '"events"'::regclass
                                      ^

每次我尝试打开我的ruby终端菜单进行测试时都会出现问题。我正在积极的记录中工作。每当我尝试使用一种方法将事件添加到数据库时,我都会收到此错误。

def add_event
    puts "What is your event's name?\n\n"
    event_name = gets.chomp
    puts "What is your event's location?\n\n"
    event_location = gets.chomp
    puts "What is your start date? example: 1990-11-16\n\n"
    event_start_date = gets.chomp
    puts "What is your end date? example: 1990-11-19\n\n"
    event_end_date = gets.chomp
    Event.create({name: event_name, location: event_location,
        start_date: event_start_date, end_date: event_end_date})
    puts "#{name} has been added!"
end

这是我的架构 -

ActiveRecord::Schema.define(version: 20140830232637) do

  # These are extensions that must be enabled in order to support this database
  enable_extension "plpgsql"

  create_table "event_tables", force: true do |t|
    t.string   "name"
    t.string   "location"
    t.datetime "start_date"
    t.datetime "end_date"
    t.datetime "created_at"
    t.datetime "updated_at"
  end
end

1 个答案:

答案 0 :(得分:0)

您正在使用名为Event的模型类:

Event.create({name: event_name, location: event_location,
        start_date: event_start_date, end_date: event_end_date})

并且想要使用名为events的表,除非您已经配置了它。但是您已经创建了一个名为event_tables的表:

create_table "event_tables", force: true do |t|
  ..
end

您应该使用名为events的表格或名为EventTable的模型。