Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails migration does not change schema.rb

I have a rails migration that is not being applied to my schema.rb. The migration should create a table:

class CreateUserGraphs < ActiveRecord::Migration   def change     create_table :user_graphs do |t|       t.string :name       t.string :content       t.integer :user_id       t.string :type_id       t.integer :upload_id        t.timestamps     end      add_index :user_graphs, [:user_id, :created_at]   end end 

I did db:reset. Then I tried rake db:migrate:up VERSION=123123123(this is the migration #). I am in my "dev" environment.

Why is the migration not affecting schema.rb?

like image 248
Don P Avatar asked Dec 09 '13 07:12

Don P


Video Answer


2 Answers

From the documentation:

The rake db:reset task will drop the database, recreate it and load the current schema into it.

This is not the same as running all the migrations. It will only use the contents of the current schema.rb file. If a migration can't be rolled back, 'rake db:reset' may not help you. To find out more about dumping the schema see 'schema dumping and you.'

So rake db:reset => db:drop db:create db:schema:load db:seed

To run all the migrations, use : rake db:drop db:create db:migrate

Or db:migrate:reset=> rake db:drop db:create db:migrate

Reference

like image 195
Vucko Avatar answered Sep 19 '22 02:09

Vucko


I had the same issue. I am working in development environment (with Passenger and Apache). Production and development environments use the same database.

When I run rake db:migrate, the db was changed, but the schema was not updated. Then I run rake db:migrate RAILS_ENV=development, and now the schema was updated.

Seems that rails/rake are confused about my environment. Passenger sets a development environment for this site, but rake aboutsays "Environment production".

like image 23
Jussi Hirvi Avatar answered Sep 17 '22 02:09

Jussi Hirvi