I've got below command run on console
rails g migration payslips first_name:string last_name:string
But this just generates empty file like below
class Payslips < ActiveRecord::Migration
def change
end
end
I cannot find the reason why. Is there something wrong with the console generate command?
Is correct functionality, if you want create a model then you need run:
rails g model payslips first_name:string last_name:string
Then you get:
class CreatePayslips < ActiveRecord::Migration
def change
create_table :payslips do |t|
t.string :first_name
t.string :last_name
t.timestamps
end
end
end
Use the word: Create before your table name.
$ rails generate migration CreateProducts name:string part_number:string
generates:
class CreateProducts < ActiveRecord::Migration
def change
create_table :products do |t|
t.string :name
t.string :part_number
end
end
end
source: http://guides.rubyonrails.org/migrations.html
Assuming that your model has been created, you must be more explicit when explaining what you really want to do :
rails g migration add_first_name_and_last_name_to_payslips first_name:string last_name:string
The above tells the migrator to add first_name and last_name to the payslips table, so you end up with this migration :
class AddFirstNameAndLastNameToPayslips < ActiveRecord::Migration
def change
add_column :payslips, :first_name, :string
add_column :payslips, :last_name, :string
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With