Run Server with Pending Migrations

Sometime it happens that you want to run server with pending migrations.

For example you run rake db:rollback

now will have one pending migration and you want to see the effect of that migration and for this you need to run the server. Now if you will try to run server it will give you the error:


Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development

so, to get rid of this error you can comment a following line from specific environment file:

# config.active_record.migration_error = :page_load

It raise an error on page load if there are pending migrations.


Decimal DataType Precision and Scale

If you have a attribute of decimal datatype (like price attribute of product) in one of database table and you want to have eight digits of significance and two digits after the decimal point then add following in your migration:

class CreateProducts < ActiveRecord::Migration
  def change
    create_table :products do |t|
      t.string :title
      t.decimal :price,  precision: 8, scale: 2