# Migration problem

**URL:** <https://discuss.rubyonrails.org/t/migration-problem/11406>\
**Category:** rubyonrails-talk\
**Created:** [April 8, 2007, 2:56pm UTC](https://discuss.rubyonrails.org/t/migration-problem/11406 "2007-04-08T14:56:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_C](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dave\_C](https://discuss.rubyonrails.org/u/Dave_C)\
**Post date:** [April 8, 2007, 2:56pm UTC](https://discuss.rubyonrails.org/t/migration-problem/11406/1 "2007-04-08T14:56:26Z")

</div>

Ok, going through the book Ruby on Rails Made Easy, and I made a mistake here. I forgot to add in two columns into my table. so i tried to add them back into the migration file and run it again, but after checking with the #ROR channel on IRC i was informed that this is not possible. I needed to make a new migration file.

I have done this, but I am obviously doing something wrong. If someone could point out my error it would be appreciated.

Original migration file.

class CreateCategories \< ActiveRecord::Migration &nbsp;&nbsp;def self.up &nbsp;&nbsp;&nbsp;&nbsp;create\_table :categories do |t| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.column :name, :string &nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;Category.create :name =\> "Furniture" &nbsp;&nbsp;&nbsp;&nbsp;Category.create :name =\> "Miscellaneous"

&nbsp;&nbsp;&nbsp;&nbsp;add\_column :classifieds, :category\_id, :integer &nbsp;&nbsp;&nbsp;&nbsp;Classified.find(:all).each do |c| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c.update\_attribute(:category\_id, 4) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;end

&nbsp;&nbsp;def self.down &nbsp;&nbsp;&nbsp;&nbsp;drop\_table :categories &nbsp;&nbsp;&nbsp;&nbsp;remove\_column :classifieds, :category\_id &nbsp;&nbsp;end end

Migration file I tried to create.

class AddColumns \< ActiveRecord::Migration &nbsp;&nbsp;def self.up &nbsp;&nbsp;create\_t.column :name, :string &nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;Category.create :name =\> "Electronics" &nbsp;&nbsp;&nbsp;&nbsp;Category.create :name =\> "Real Estate" &nbsp;&nbsp;end

&nbsp;&nbsp;def self.down &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;drop\_table :categories &nbsp;&nbsp;&nbsp;&nbsp;remove\_column :classifieds, :category\_id &nbsp;&nbsp;end end

receive an unexpected kEND expecting $ error when trying to run rake db:migrate on the new file.

Thank you,

Dave

---

<div class="post-metadata">

**Author:** ![Andriy\_Tyurnikov](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@Andriy\_Tyurnikov](https://discuss.rubyonrails.org/u/Andriy_Tyurnikov)\
**Post date:** [April 8, 2007, 3:01pm UTC](https://discuss.rubyonrails.org/t/migration-problem/11406/2 "2007-04-08T15:01:40Z")

</div>

> I have done this, but I am obviously doing something wrong. If someone could point out my error it would be appreciated.
> 
> Migration file I tried to create.
> 
> class AddColumns \< ActiveRecord::Migration def self.up create\_t.column :name, :string end

Oops, self.up is ended here, but you continue to write migration up code, delete this end statement

---

<div class="post-metadata">

**Author:** ![Ben\_Munat](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@Ben\_Munat](https://discuss.rubyonrails.org/u/Ben_Munat)\
**Post date:** [April 8, 2007, 8:00pm UTC](https://discuss.rubyonrails.org/t/migration-problem/11406/3 "2007-04-08T20:00:04Z")

</div>

You only need to create create a new migration file to add columns if you've already put your app into production.

If you're just following a tutorial, just edit the migration you have. Then run rake db:migrate VERSION=0 to drop everything and then rake db:migrate to set up the db again with your new migration.

b

wheresdave wrote:

---

<div class="post-metadata">

**Author:** ![Dave\_C](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dave\_C](https://discuss.rubyonrails.org/u/Dave_C)\
**Post date:** [April 8, 2007, 9:24pm UTC](https://discuss.rubyonrails.org/t/migration-problem/11406/4 "2007-04-08T21:24:04Z")

</div>

awesome.

thank you so much.
