# Failed to run migration

**URL:** <https://www.ruby-forum.com/t/failed-to-run-migration/226226>\
**Category:** Rails\
**Created:** [May 24, 2011, 8:36am UTC](https://www.ruby-forum.com/t/failed-to-run-migration/226226 "2011-05-24T08:36:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_shelfer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@John\_shelfer](https://www.ruby-forum.com/u/John_shelfer)\
**Post date:** [May 24, 2011, 8:36am UTC](https://www.ruby-forum.com/t/failed-to-run-migration/226226/1 "2011-05-24T08:36:51Z")

</div>

i have a migration but after running it (rake db:migrate),it created  
a table “posts” but couldn’t create columns.

class CreatePosts \< ActiveRecord::Migration  
def self.up  
create\_table :posts do |t|  
t.string :name  
t.string :title  
t.text :content  
t.timestamps  
end  
end  
def self.down  
drop\_table :posts  
end  
end

Please help!!

John

---

<div class="post-metadata">

**Author:** ![John\_shelfer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@John\_shelfer](https://www.ruby-forum.com/u/John_shelfer)\
**Post date:** [May 24, 2011, 8:51am UTC](https://www.ruby-forum.com/t/failed-to-run-migration/226226/2 "2011-05-24T08:51:05Z")

</div>

On 24 May 2011 07:25, John shelfer [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end  
> end  
> def self.down  
> drop\_table :posts  
> end  
> end

What was the output when you ran the migration? Are you sure that the  
table did not already exist when you ran the migration, so that it  
failed because it could not create the table?

If this is a new database, so there are no other tables in it then I  
suggest you delete the whole database, recreate the database (with no  
tables) and run the migration again. Note carefully what it says when  
you run the migration.

Colin

---

<div class="post-metadata">

**Author:** ![John\_shelfer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@John\_shelfer](https://www.ruby-forum.com/u/John_shelfer)\
**Post date:** [May 24, 2011, 9:09am UTC](https://www.ruby-forum.com/t/failed-to-run-migration/226226/3 "2011-05-24T09:09:00Z")

</div>

On Tue, May 24, 2011 at 2:43 AM, Colin L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > ```
> > t.timestamps
> > end
> > 
> > ```
> > 
> > end  
> > def self.down  
> > drop\_table :posts  
> > end  
> > end
> 
> What was the output when you ran the migration? Are you sure that the  
> table did not already exist

```
  I was not sure.

```

> when you ran the migration, so that it  
> failed because it could not create the table?
> 
> If this is a new database, so there are no other tables in it then I  
> suggest you delete the whole database, recreate the database (with no  
> tables) and run the migration again.

```
  Well i did exactly ,now it works .Great Colin.Thank you very
  much.
  Can you explain why in previous case,after running migration i
   couldn't add the
  columns in table ?

 John

```

---

<div class="post-metadata">

**Author:** ![John\_shelfer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@John\_shelfer](https://www.ruby-forum.com/u/John_shelfer)\
**Post date:** [May 24, 2011, 9:36am UTC](https://www.ruby-forum.com/t/failed-to-run-migration/226226/4 "2011-05-24T09:36:13Z")

</div>

On Tue, May 24, 2011 at 3:08 AM, amritpal pathak  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> > > create\_table :posts do |t|
> > 
> > tables) and run the migration again.
> 
> ```
> It is too my account.Sorry for sending from other one.
> 
> ```

```
 Well i did exactly ,now it works .Great Colin.Thank you very
  much.
  Can you explain why in previous case,after running migration i
   couldn't add the
  columns in table ?

 John

```

---

<div class="post-metadata">

**Author:** ![John\_shelfer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@John\_shelfer](https://www.ruby-forum.com/u/John_shelfer)\
**Post date:** [May 24, 2011, 9:41am UTC](https://www.ruby-forum.com/t/failed-to-run-migration/226226/5 "2011-05-24T09:41:46Z")

</div>

On Tue, May 24, 2011 at 3:35 AM, amritpal pathak

---

<div class="post-metadata">

**Author:** ![John\_shelfer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9a140/32.png) [@John\_shelfer](https://www.ruby-forum.com/u/John_shelfer)\
**Post date:** [May 24, 2011, 4:08pm UTC](https://www.ruby-forum.com/t/failed-to-run-migration/226226/6 "2011-05-24T16:08:17Z")

</div>

On Tue, May 24, 2011 at 12:08 AM, amritpal pathak  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Can you explain why in previous case,after running migration i  
> couldn’t add the columns in table ?

You can’t “create” a table that already exists, you can only modify or  
delete it.

As I suggested before, reading the documentation on migrations –  
class ActiveRecord::Migration – would be a very good idea.

And if you’re in doubt about the state of your db/tables before or after  
running a migration, I’d suggest you _look_. That’s part of the job.

–  
Hassan S. ------------------------ [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[Hassan Schroeder | about.me](http://about.me/hassanschroeder)  
twitter: @hassan
