I'm having a strange problem with Rails 4.2.4. I am creating a new table, which references some others, like this:
t.references :local, index: true, foreign_key: true, null: false
t.references :serie, index: true, foreign_key: true, null: false
when I execute the migration, there is an error when creating the foreign key constraint:
PG::UndefinedColumn: ERROR: no existe la columna «series_id» referida en la llave foránea
which is Spanish for
PG::UndefinedColumn: ERROR: column «series_id» referenced in foreign key constraint does not exist
meaning there is no "series_id" column in the created table. Of course, it shouldn't be any column with that name.
The correct column name the generation of FK should be looking for is "serie_id", and it does exist.
Now the strangest thing is that it doesn't fail for :local, for instance. It doesn't look for "locales_id", but "local_id" which is correct, and the corresponding FK is created.
I have custom Spanish inflections, and correct pluralizations are:
local -> locales
serie -> series
however I don't understand why the FK generation seems to be pluralizing in one case and not in the other.
I have found a working solution in this answer, which is declaring specifically the foreign keys, like:
add_foreign_key :turnos_registrados, :series, column: :serie_id
but what I'd like to know is why is this happening.