1

i am having a table as follows:

class CreateInvoiceDetails < ActiveRecord::Migration
  def change
    create_table :invoice_details do |t|
      t.string :invoice_number
      t.string :supplier_name
      t.date :invoice_due_date
      t.string :description_of_goods
      t.timestamps
    end
  end
end

Now I want to remove description_of_goods column from invoice_details table. I used the following command:

rails generate migration  RemoveDescriptionOfGoodsFromInvoiceDetails description_of_goods:string

and I also I tried:

rails g migration remove_description_of_goods_from_invoice_details description_of_goods:string

In both the cases migrations are created but when I run rake db:migrate, i am facing the following error:

== 20150319194628 RemoveDescriptionOfGoodsFromInvoiceDetails: migrating =======
-- remove_column(:invoice_details, :description_of_goods, :string)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

undefined method `to_sym' for nil:NilClass/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:216:in `column'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:548:in `block (2 levels) in copy_table'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:541:in `each'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:541:in `block in copy_table'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:198:in `create_table'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:538:in `copy_table'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:531:in `move_table'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:524:in `block in alter_table'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:199:in `transaction'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:523:in `alter_table'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:466:in `remove_column'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:649:in `block in method_missing'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:621:in `block in say_with_time'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:621:in `say_with_time'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:641:in `method_missing'
/home/raj/Desktop/Projects/invoicemanagement/db/migrate/20150319194628_remove_description_of_goods_from_invoice_details.rb:3:in `change'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:595:in `exec_migration'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:579:in `block (2 levels) in migrate'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:578:in `block in migrate'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:577:in `migrate'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:752:in `migrate'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:1038:in `block in ddl_transaction'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `block in transaction'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:209:in `within_new_transaction'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `transaction'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/transactions.rb:208:in `transaction'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:1038:in `ddl_transaction'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:991:in `execute_migration_in_transaction'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:953:in `block in migrate'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:949:in `each'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:949:in `migrate'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:807:in `up'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:785:in `migrate'
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

Please help me out of this error.

sachin god
  • 685
  • 2
  • 12
  • 29

4 Answers4

0

If you are using SQLite, this was a problem with the SQLite database not supporting the ability to drop columns: http://www.sqlite.org/faq.html#q11

Gaurav Gupta
  • 475
  • 4
  • 11
0

This is a problem that I have had with rails migrations. You misspelled or misordered a field with its name. Here is what you can do.

If you have only done one migration since the problem.
rake db:rollback.
That will get you to the mistake and you can change the problem which I will talk about more later.
If it is not the last migration keep going with rake db:rollback until you are there and the problem is fixed.

The problem is something like this. Notice the order on the first one and the spelling on the second one. These are two problems that have giving me the same situation you are in right now which is that to_sym bs.

djadam
  • 649
  • 1
  • 4
  • 20
0

To revert recent migration this should work (1 step)

rake db:rollback

to revert k steps you should run

rake db:rollback STEP=k

where k is the no.of steps you want to revert and at last worked for me, then use

rake db:migrate

to execute migration again.

Atul Dwivedi
  • 1
  • 1
  • 1
-2

I had the same problem and after several hours I finally found the solution using self.up instead of change

def self.up
    create_table :users do |t|
        ...
    end
end

and run rake db:migrate.

tbraun89
  • 2,246
  • 3
  • 25
  • 44
Stefano
  • 1
  • 1
  • Welcome to Stack Overflow! Welcome to Stack Overflow. Please write your answer in English, as Stack Overflow is an [English only site](https://meta.stackoverflow.com/a/297680/). – double-beep Feb 21 '19 at 13:46
  • This does not provide an answer to the question. You can [search for similar questions](//stackoverflow.com/search), or refer to the related and linked questions on the right-hand side of the page to find an answer. If you have a related but different question, [ask a new question](//stackoverflow.com/questions/ask), and include a link to this one to help provide context. See: [Ask questions, get answers, no distractions](//stackoverflow.com/tour) – double-beep Feb 21 '19 at 13:46
  • Anglais seulemant, svp Et vouz ne pas posez questions dans le response – brasofilo Feb 21 '19 at 13:50