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:inexecute’
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:inexecute’
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:inselect_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:incache_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:infind_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:infind’
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:inindex’

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 S…

On Tue, Nov 10, 2009 at 9:01 AM, Lady H.
<[email protected]

Dhruva S. wrote:

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

Thanks & Regards,
Dhruva S…

Try restarting the app first.

On Tue, Nov 10, 2009 at 9:01 AM, Lady H.
<[email protected]

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Dhruva S. wrote:

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

Thanks & Regards,
Dhruva S…

On Tue, Nov 10, 2009 at 9:01 AM, Lady H.
<[email protected]

As you said I tried rake db:reset ,but it still gives the same error. I
even restarted the server.
IS rake db:reset different from rake db:migrate:reset? I tried both .
Thanks!

On Nov 10, 3:31 am, Lady H. [email protected]
wrote:

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.

On Tue, Nov 10, 2009 at 4:59 PM, Lady H.
<[email protected]

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

Frederick C. wrote:

On Nov 10, 3:31�am, Lady H. [email protected]
wrote:

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

You are so true…That worked . Thanks a lot!! :slight_smile: