Rails migration does not change schema.rb

Viewed 38680

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?

7 Answers

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".

I had the same issue... it turns out it was because I edited the name of my migration file to look neater. Make sure you don't delete the time stamp in the migration file title like I did.

I deleted the migration file, the model, the controller, and associated tests and re-generated the controller and model which fixed the problem.

First you try to down you migration

rake db:migrate:down VERSION=20180605141404 # "VERSION=20180605141404 your migration version"

And again up your migration

rake db:migrate:up VERSION=20180605141404 #"VERSION=20180605141404 your migration version"

Try stop Spring before run your migration. It works for me

bin/spring stop
Related