Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

how to remove a column in rails

l am currently doing the active record course and ended up with the following error

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20150801183106  Create customers
   up     20150801184336  Add email address
   up     20150801184941  Create time entries
   up     20150801185342  Create employees
   up     20150803211552  Create accounts
   up     20150803212728  Remove old tables
   up     20150808174148  Account entries
   up     20150808183604  Create projects
   up     20150808183658  Employees projects
   up     20150808230343  Omg i forgot the type field
   up     20150809212450  Add index employees
   up     20150810190948  Add money
   up     20150810221640  Entry approval
   up     20150810224142  Create versions
  down    20150810224204  Customer information

And the actual rake db:migrate out the foolowing

== 20150810224204 CustomerInformation: migrating ==============================
-- add_column(:accounts, :zipcode, :integer)
rake aborted!
StandardError: An error has occurred, all later migrations canceled:

Mysql2::Error: Duplicate column name 'zipcode': ALTER TABLE `accounts` ADD `zipcode` int(11)/Users/kelvinatawura/sites/biller/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:299:in `query'

l posted on here https://teamtreehouse.com/forum/mysql2error-duplicate-column-name-zipcode-alter-table-accounts-add-zipcode and Hampton Catlin said to use sql skills to remove the duplicated column from the database. Any ideas how to do this please?

1 Answer

You have to create a new migration that removes the column.

OR you could, like Hampton said, run rake db:reset (much easier).