lundi 4 février 2019

I have created a table in rails using the migration file. But I am not able to access the table in the rails console

I have created a table called as Flowlogs in the rails application using the migration file. I've also fed the data to that table in the rails console. All of a sudden when I try to manually feed the data in the rails console then I get the error.

I've created a table named "flowlogs" and there are two columns in the table with the names vpc_id and flowlog_id. I've logged into the rails console and gave a=Flowlogs.new() and then a.vpc_id="1234" and a.flowlog_id="a1234" and finally gave a.save. This has successfully worked and I have cross-checked using by using the command Flowlogs.all. It has shown the output. But after sometime when I logged into the console and gave Flowlogs.all, then it kept throwing the errors.

Most importantly when I logged into the mysql console and checked there is table with the data with I fed manually in the rails console

My database name is fusion.

Flowlog Load (1.4ms)  SELECT `flowlog`.* FROM `flowlog`
Hirb Error: Mysql2::Error: Table 'fusion.flowlog' doesn't exist: SELECT `flowlog`.* FROM `flowlog`
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/mysql2-0.4.10/lib/mysql2/client.rb:120:in `_query'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/mysql2-0.4.10/lib/mysql2/client.rb:120:in `block in query'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/mysql2-0.4.10/lib/mysql2/client.rb:119:in `handle_interrupt'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/mysql2-0.4.10/lib/mysql2/client.rb:119:in `query'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:305:in `block in execute'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:472:in `block in log'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `log'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:305:in `execute'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/mysql2_adapter.rb:231:in `execute'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/mysql2_adapter.rb:235:in `exec_query'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:356:in `select'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:32:in `select_all'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/connection_adapters/abstract/query_cache.rb:70:in `select_all'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/querying.rb:39:in `find_by_sql'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/relation.rb:639:in `exec_queries'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/relation.rb:515:in `load'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/relation.rb:243:in `to_a'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.6/lib/active_record/relation/delegation.rb:46:in `to_ary'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/hirb-0.7.3/lib/hirb/formatter.rb:88:in `Array'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/hirb-0.7.3/lib/hirb/formatter.rb:88:in `determine_output_class'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/hirb-0.7.3/lib/hirb/formatter.rb:53:in `format_output'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/hirb-0.7.3/lib/hirb/view.rb:205:in `render_output'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/hirb-0.7.3/lib/hirb/view.rb:123:in `view_output'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/hirb-0.7.3/lib/hirb/view.rb:201:in `view_or_page_output'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/hirb-0.7.3/lib/hirb/view.rb:187:in `output_value'
    /Users/masettya/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb:490:in `block (2 levels) in eval_input'
    /Users/masettya/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb:623:in `signal_status'
    /Users/masettya/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb:486:in `block in eval_input'
    /Users/masettya/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/ruby-lex.rb:246:in `block (2 levels) in each_top_level_statement'
    /Users/masettya/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/ruby-lex.rb:232:in `loop'
    /Users/masettya/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/ruby-lex.rb:232:in `block in each_top_level_statement'
    /Users/masettya/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/ruby-lex.rb:231:in `catch'
    /Users/masettya/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb/ruby-lex.rb:231:in `each_top_level_statement'
    /Users/masettya/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb:485:in `eval_input'
    /Users/masettya/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb:395:in `block in start'
    /Users/masettya/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb:394:in `catch'
    /Users/masettya/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/irb.rb:394:in `start'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/railties-4.2.6/lib/rails/commands/console.rb:110:in `start'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/railties-4.2.6/lib/rails/commands/console.rb:9:in `start'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:68:in `console'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `block in require'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:274:in `require'
    /Users/masettya/fusion_app/bin/rails:9:in `<top (required)>'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `block in load'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
    /Users/masettya/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'
    /Users/masettya/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    /Users/masettya/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    -e:1:in `<main>'

This is my migration file

class CreateFlowlogs < ActiveRecord::Migration
  def change
    create_table :flowlogs do |t|
        t.string :account_name
        t.string :region
        t.string :vpc_id
        t.string :flowlog_id
        t.boolean :status
    end
  end
end

Aucun commentaire:

Enregistrer un commentaire