You have it in the opposite direction. First you need to build your migrations, and your models are the second. Migrations promote the state of the database. Your models reflect the current state of the database. There is no 1-to-1 mapping for migration.
I would like to automatically generate migration files from these models using a rail migration generator.
Unable to execute.
You use rails generate migration to create a migration that, almost as a side effect, creates a stub model file. You cannot use an existing model file to create a model migration because the model does not contain any information about the actual columns that make up the model. Rails will have to extract and imply all the necessary information from your associations / validations, and even then this will lead to incorrect processing of most columns.
Also, when I have a more complex model, ... it would be really nice if it automatically creates JOIN tables and fields with the correct names
Again, you cannot. You are responsible for defining the database schema, and the way you do this is to create migrations. You can do this manually or through rails generate , but the process you must follow first creates your migrations and your models second.
As an example, here is a complete model, ready for release:
class MyModel < ActiveRecord::Base end
This model definition can wrap a table containing 10 columns or 1000 columns; you (and Rails) absolutely do not know, based on the definition of the model.
Here's another model containing at least one column, but again, you don't know which column:
class MyModel < ActiveRecord::Base validates :code, presence: true, uniqueness: true end
Is code string or a number? Should there be an index in the column? There is no way to find out.