# Migration problem

**URL:** <https://www.ruby-forum.com/t/migration-problem/91409>\
**Category:** Rails\
**Created:** [April 8, 2007, 4:57pm UTC](https://www.ruby-forum.com/t/migration-problem/91409 "2007-04-08T16:57:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wheresdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/6a8cbe/32.png) [@wheresdave](https://www.ruby-forum.com/u/wheresdave)\
**Post date:** [April 8, 2007, 4:57pm UTC](https://www.ruby-forum.com/t/migration-problem/91409/1 "2007-04-08T16:57:32Z")

</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  
def self.up  
create\_table :categories do |t|  
t.column :name, :string  
end

```
Category.create :name => "Furniture"
Category.create :name => "Miscellaneous"

add_column :classifieds, :category_id, :integer
Classified.find(:all).each do |c|
  c.update_attribute(:category_id, 4)
  end

```

end

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

Migration file I tried to create.

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

```
Category.create :name => "Electronics"
Category.create :name => "Real Estate"

```

end

def self.down  
drop\_table :categories  
remove\_column :classifieds, :category\_id  
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:** ![wheresdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/6a8cbe/32.png) [@wheresdave](https://www.ruby-forum.com/u/wheresdave)\
**Post date:** [April 8, 2007, 5:03pm UTC](https://www.ruby-forum.com/t/migration-problem/91409/2 "2007-04-08T17:03:32Z")

</div>

> ```
> create_t.column :name, :string
> end
> 
> ```

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

```
Category.create :name => "Electronics"
```

---

<div class="post-metadata">

**Author:** ![wheresdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/6a8cbe/32.png) [@wheresdave](https://www.ruby-forum.com/u/wheresdave)\
**Post date:** [April 8, 2007, 10:01pm UTC](https://www.ruby-forum.com/t/migration-problem/91409/3 "2007-04-08T22:01:20Z")

</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

---

<div class="post-metadata">

**Author:** ![wheresdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/6a8cbe/32.png) [@wheresdave](https://www.ruby-forum.com/u/wheresdave)\
**Post date:** [April 8, 2007, 11:25pm UTC](https://www.ruby-forum.com/t/migration-problem/91409/4 "2007-04-08T23:25:27Z")

</div>

awesome.

thank you so much.
