I'm trying to add an ActiveRecord model called Media. The migration script looks like this
class CreateMedias < ActiveRecord::Migration
def up
create_table :medias do |t|
t.string :filename
t.timestamps null: false
end
end
def down
drop_table :medias
end
end
This will create a table in my PostgreSQL database called medias just as I expected. My ActiveRecord class looks like this
class Media < ActiveRecord::Base
end
From what I understand this is how it should look like. The name of the ActiveRecord class should in singular and the table name in plural. However, when I try to create a new Media object
Media.create filename: "abc.png"
I get the following error
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "media" does not exist
LINE 5: WHERE a.attrelid = '"media"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"media"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
For some reason ActiveRecord thinks that the table_name should be media and not medias. If I run the same query directly in the database with 'medias' instead of 'media' I get the expected result. For all my other models, the table_name is pluralized but for some reason my Media model is an exception. Does anyone know what might cause this?