When running:
rails generate migration <someaction> field:type
I can see it is performing two actions:
- Call invoke active_record
- Create a migration file.
I understand perfectly why it is generating the migration file, but why does it invoke ActiveRecord? This bothers me because what if I want to create the migration file manually? how would I mimic this invocation (if it’s even necessary..)?
The
MigrationGeneratorgenerator:1) Loads your ORM (which by default in Rails is Active Record) to have it extend the correct ‘ORM’::Migration class (again by default this is ActiveRecord::Migration)
2) It is itself an extension of the
NamedBasegenerator which sees if your running Active Record to decide if it should pluralize the table names. This is so if you runor
You get the same results in your file.
So the short answer is, you do not need to invoke active_record to create a migration by hand, but if you do and you are using Active Record make sure that your table names are pluralized in your migration file.