Renaming a model and table leads to SQL Exception

I have a model called "Media", database table "Medias". I had to rename that model to "Medium" and the database table to "Mediums". and now when I run my application , I get the following error:

ActiveRecord::StatementInvalid in MediumsController#index SQLite3::SQLException: no such table: media: SELECT * FROM "media"

Application Trace: C:/IR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract_adapter.rb:219:in `log' C:/IR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/sqlite_adapter.rb:172:in `execute' C:/IR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/sqlite_adapter.rb:417:in `catch_schema_changes' C:/IR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/sqlite_adapter.rb:172:in `execute' C:/IR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/sqlite_adapter.rb:320:in `select' C:/IR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache' C:/IR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/query_cache.rb:60:in `select_all' C:/IR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/query_cache.rb:81:in `cache_sql' C:/IR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/query_cache.rb:60:in `select_all' C:/IR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:661:in `find_by_sql' C:/IR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:1548:in `find_every' C:/IR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:615:in `find' C:/IR/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:635:in `all' C:/IR/rails_apps/work/ProjectBroadcast/app/controllers/mediums_controller.rb:6:in `index'

Note: I am using sqlite3

I don't have any table called 'media' in my application, I wonder why its doing a select from that table

I tried rake db:migrate:reset and it was successful.

Any help is hugely appreciated

Thanks!

I think you missed to reset your database using rake db:reset after having changed the model name & the corresponding migrations.

Thanks & Regards, Dhruva Sagar.

I have a model called "Media", database table "Medias". I had to rename that model to "Medium" and the database table to "Mediums". and now when I run my application , I get the following error:

ActiveRecord::StatementInvalid in MediumsController#index SQLite3::SQLException: no such table: media: SELECT * FROM "media"

Rails things that the plural of medium is media, so is looking for a table called media for the model medium. Either tell the inflector what you want the plural of medium to be or use set_table_name

Fred

Hi Have u changed the model name in ur controller query. which is in index method. Please check first.

Because the error is in ur mediums controller “ActiveRecord::StatementInvalid in MediumsController#index”