Rails: Error "Could not find table"

I developed a simple rails application that works fine on my development machine.

When I put it on the production server (Phusion Passenger / Nginx), it returns me this error in the my_app/log/production.log file:

 ActiveRecord::StatementInvalid (Could not find table 'categories') 

What's wrong?

PS: After the naming error, the table name was manually edited, but it works fine in design mode. I do not suspect a mistake.

+6
source share
2 answers
  • Make sure you migrate the database on the production server

  • Manually editing tables is a huge no no in Rails. This will give you more headaches than it's worth. If you need to change something, you better create a new migration to change it, even if it's just a name change. (However, you can undo the db changes, delete the last migration and create a new one, but, as I said, this is more of a problem than it costs)

  • Make sure your XML schema file is correct or at least matches the actual schema. You can remove this and run rake: db: migrate to create a new one.
+5
source

You can assign a table name to ActiveRecord models to prevent these misuse errors.

 class Category < ActiveRecord::Base self.table_name = 'categories' end 
0
source

Source: https://habr.com/ru/post/893315/


All Articles