I am using rails 5.1.4 with mysql2 adapter.
When I try to create a table having reference to another table in the migration, it gives table doesn't exist. I don't understand why this error pops up. It's meaningless to see an error that can't help with any troubleshooting.
I read another post (Migration to create table raises Mysql2::Error: Table doesn't exist) and the solution proposed worked for me. I have a concern though with this solution as it proposes to replace the "references" with "integer" and adding "_id" to the class name being referenced. This makes the DB unaware about the FK constraint (as seen from the mysql executed in the log).
Moreover, this error is happening in few migrations only. Other migrations with references are working fine.
As stated before, the solution that worked doesn't seem right to me.
The migration code that failed is this:
class CreateLocatableEntitiesPlaceEntitiesPlaces < ActiveRecord::Migration[5.1]
def change
create_table :locatable_entities_place_entities_places do |t|
t.string :name
t.integer :type
t.references :locality, foreign_key: true, index: {:name => "index_places_on_locality_id"}
t.references :establishment, foreign_key: true, index: {:name => "index_places_on_establishment_id"}
t.references :parking, foreign_key: true, index: {:name => "index_places_on_parking_id"}
t.boolean :show_in_map
t.boolean :show_locality_name
t.date :constructed_on
t.integer :total_area
t.float :lat
t.float :long
end
end
end
Also wanted to add that I've namespaced my models in sub-folders, that's why I've manually named the indexes as they were getting too large to handle by MySQL. Just in case it has to do anything with it.
Below is the screen-shot of my migrations folder having all migrations in order they're run.