2

In my app, I edited a migration file shown here:

class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
      t.string :first_name
      t.string :last_name
      t.string :dj_alias
      t.boolean :site_admin
      t.integer :station_id
      t.string :byline
      t.string :bio

      t.timestamps null: false
    end
  end
end

to have the bio and byline fields. However, when I run rake db:reset, there is no change in the schema.rb file. The only error I see in that there is this code block:

ActiveRecord::Base.connection.tables.each do |table|
  result = ActiveRecord::Base.connection.execute("SELECT id FROM #{table} ORDER BY id DESC LIMIT 1") rescue ( puts "Warning: not procesing table #{table}. Id is missing?" ; next )
  ai_val = result.any? ? result.first['id'].to_i + 1 : 1
  puts "Resetting auto increment ID for #{table} to #{ai_val}"

  ActiveRecord::Base.connection.execute("ALTER SEQUENCE #{table}_id_seq  RESTART WITH #{ai_val}")
end

at the bottom of the seeds.rb file, which is meant to handle indexing of the seeds file. when I run rake db:reset, the rescue statement in the first line displays: Warning: not procesing table schema_migrations. Id is missing?

I guess I am confused why this statement is rescuing this? Although it seems like it might be the cause, but doesn't the schema.rb reset happen before the seeds.rb file is accessed?

Here is the output of rake db:migrate:status

 Status   Migration ID    Migration Name
--------------------------------------------------
up     20150225041954  Create songs
up     20150225042739  Create albums
up     20150225043102  Create artists
up     20150225043854  Create playlists
up     20150225044118  Create users
up     20150225044314  Create stations
up     20150225061259  Create featured artists
up     20150225153938  Add devise to users
up     20150225200646  Create reviews
up     20150321171830  Stations users
up     20150323200255  Add last fm to album
up     20150323200432  Add last fm to artist
up     20150323200513  Add last fm to song
up     20150325052314  Albums stations
up     20150325061241  Playlist songs
up     20150327172516  Add image url to albums
up     20150327172532  Add image url to artists
Oscar Courchaine
  • 346
  • 3
  • 14

1 Answers1

1

For applying the new changes in the migration file, you need to run rake db:migrate. If the migration has already been run before you made the change, then run rake db:rollback to roll back the migration and apply it again.

rake db:reset does not apply new changes in migration files. It tries to load what is already in the schema.rb file.

See http://edgeguides.rubyonrails.org/active_record_migrations.html#setup-the-database & http://edgeguides.rubyonrails.org/active_record_migrations.html#resetting-the-database for more details about how rake db:reset works.

Run rake db:migrate:status to see what migrations are run.

Prakash Murthy
  • 12,923
  • 3
  • 46
  • 74