Reputation: 3032
Just playing around with building a rails app and I am pretty sure I did something dumb. I ran a scaffold and misspelled the model Ave vs Afe. I am sure I went through and changed everything in the migration files and view files etc. and even ran a search for 'ave' to see if I missed anything. Anyway ran the migrations and now I get this:
PG::UndefinedTable: ERROR: relation "aves" does not exist LINE 5: WHERE a.attrelid = '"aves"'::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 = '"aves"'::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum
Extracted source (around line #17):
15 # GET /afes/new
16 def new
17 @afe = Afe.new
18 end
19
20 # GET /afes/1/edit
I checked my postgsql indexes, schema and have even wiped my migrations and run rake:db:reset. My schema, models and controllers are clean. That old 'ave/aves' reference is no where to be found. It looks like something hung up in active record but not sure where to start.
It's a dummy play app but I really don't want to start over. Can I force the migrations to run again (if I un-delete them)?
Upvotes: 3
Views: 4526
Reputation: 15515
This has to do with pluralization rules, the rules used to make a plural form of a model name.
ActiveSupport::Inflector.pluralize "afe"
=> "aves"
So Rails thinks the plural of afe
is aves
.
You can fix your problem by renaming the table back to aves
in your migration, or by adding this to config/initializers/inflections.rb
:
ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'afe', 'afes'
end
Upvotes: 6