Search code examples
ruby-on-railsdatabase-migration

Removing column is not working


I am trying to remove a column from my database. I'm running this

rails generate RemoveOccupancyFromSpaces occupancy:string

But then am getting this error message

Could not find generator 'RemoveOccupancyFromSpaces'. Maybe you meant 'resource_route' or 'devise:controllers' or 'active_admin:page'
Run `rails generate --help` for more options.

Where am I going wrong here?


Solution

  • The correct syntax is rails generate migration RemoveOccupancyFromSpaces occupancy:string

    This should yield a file with the correct syntax:

    class RemoveOccupancyFromSpaces < ActiveRecord::Migration
      def change
        remove_column :spaces, :occupancy, :string
      end
    end