Reputation: 11
I have a SQLite3 database and I changed a table called People
to Persons
(to better match the standard of having a singular Person
model).
I made this change manually in the database using SQLite3 and the call:
ALTER TABLE People RENAME TO Persons;
Now when I run the app I get an error:
SQLite3::SQLException: no such table: people: SELECT "people".* FROM "people"
I changed the table name in the controller, model, migration and schema files to match the change. Where else should I make the change?
Upvotes: 1
Views: 234
Reputation: 160833
If you change the table name, then Rails' default convention is broken. You have to tell Rails to use the persons
table instead of people
because Rails thought the table for Person
model is people
.
[1] pry(main)> 'person'.pluralize
=> "people"
If you still want to change the table name, then you need to config it like:
class Person < ActiveRecord::Base
self.table_name = "persons"
end
Upvotes: 2
Reputation: 642
I think you would be better generating a model "person" and letting Rails handle the pluralization. It probably converts to people and is getting confused.
You would then migrate data over and then drop your old table. You would have to check the naming for your views and controllers also.
Upvotes: 2