Don't understand migrations

If I use rake db:rollback it will delete a table I don’t want. Then I
add another migration with a new table. Then I run db:migrate. The table
I didn’t want is created again. How do I delete it so it doesn’t come
back?

Example :

class CreateNewTable< ActiveRecord::Migration
def self.up
create_table :new_tables do |t|
t.column :name, :string
end

drop_table :old_tables

#rename_table :old_tables, :new_tables
rename_table :books, :libraries

#remove_column(table_name, column_name)
remove_column :items, :price

#remove_column(table_name, column_name)
rename_column “users”, “password”, “hashed_password”

#add_column table_names, new_column_names
add_column “users”, “email”

end

def self.down
drop_table :lupa_passwords
end
end


ANOTHER SCENARIO

I created a series of migrations named 001_migration.rb through
007_migration.rb. The last migration worked fine until I attempted to
rollback to the previous version using

rake db:migrate VERSION=6

which dropped all the tables in my database.

Now the migration refuses to do anything, regardless of which version
number I tell it to use. It always tried to run the latest version,
which fails because the relevant tables do not exist. What is wrong?

ANSWER: My migration names were the same. Each migration filename must
be different or you will receive errors.

Reinhart
http://teapoci.blogspot.com


FREE eBook Ruby

http://teapoci.blogspot.com/search/label/eBook

Visit Indonesia 2008 wrote:

Example :

class CreateNewTable< ActiveRecord::Migration
def self.up
create_table :new_tables do |t|
t.column :name, :string
end

drop_table :old_tables

Thanks. Now I got it.

Pål Bergström wrote:

class CreateNewTable< ActiveRecord::Migration
def self.up
create_table :new_tables do |t|
t.column :name, :string
end

drop_table :old_tables

Thanks. Now I got it.

Your customers won’t mind copying all the data from the old table to the
new
one. (-:


Phlip