Failed to run migration

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

On 24 May 2011 07:25, John shelfer [email protected] 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

On Tue, May 24, 2011 at 2:43 AM, Colin L. [email protected]
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

On Tue, May 24, 2011 at 3:08 AM, amritpal pathak
[email protected]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

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

On Tue, May 24, 2011 at 12:08 AM, amritpal pathak
[email protected] 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. ------------------------ [email protected]
http://about.me/hassanschroeder
twitter: @hassan

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs