2 Replies - 2106 Views - Last Post: 18 July 2015 - 11:54 AM Rate Topic: -----

#1 lakerice   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 27-June 15

Ruby on Rails issue - Migrations Pending error

Posted 17 July 2015 - 05:26 PM

Hi, I'm new to Ruby on Rails and I am currently working on the bass music app exercise in Codeacademy (the link is Ruby on Rails course). I finished all the steps but I keep getting the following error when I try to refresh https://localhost:8080/

"Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development"

I've tried
rake db:migrate
several times and tried restarting with
cd bass-music
, then
rake db:migrate
only to get the same error. I even tried deleting the gem file and doing a
bundle install
again but nothing. So I did
rake db:migrate:status
and found the following in the bash:

$ rake db:migrate:status                                    
                                                            
database: /home/ccuser/workspace/learn-rails_bass-music/bass
-music/db/development.sqlite3                               
                                                            
 Status   Migration ID    Migration Name                    
--------------------------------------------------          
  down    20150717023051  Create albums                     
  down    20150717023103  Create tracks


This is the code for the 2 files:

20150717023051 Create albums


class CreateTracks < ActiveRecord::Migration
  belongs_to :Albums
  def change
    create_table :tracks do |t|
      t.string :name
      t.string :minutes
      t.references :album
      t.belongs_to :album
      t.timestamps
    end
  end
end



20150717023103 Create tracks

class CreateAlbums < ActiveRecord::Migration
  has_many :Tracks
end
  def change
    create_table :albums do |t|
      t.string :cover
      t.string :title
      t.string :artist
      t.belongs_to :album
      t.timestamps
    end
  end
end



Is there anything wrong with the syntax? Or is there another solution?

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Ruby on Rails issue - Migrations Pending error

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5237
  • View blog
  • Posts: 14,031
  • Joined: 18-April 07

Re: Ruby on Rails issue - Migrations Pending error

Posted 17 July 2015 - 09:48 PM

I don't think I have seen associations inside of migrations. Are you sure it said to put them there? Associations typically belong in models. In the directions for your course it is saying put those associations in your Album and Track models... not in the migration. I do know that your create tracks migration has an "end" statement on line 3 that should not be there either.

Try this...

class CreateAlbums < ActiveRecord::Migration
  def change
    create_table :albums do |t|
      t.string :cover
      t.string :title
      t.string :artist
      t.belongs_to :album
      t.timestamps
    end
  end
end



..and

class CreateTracks < ActiveRecord::Migration
  def change
    create_table :tracks do |t|
      t.string :name
      t.string :minutes
      t.references :album
      t.belongs_to :album
      t.timestamps
    end
  end
end



And again put your associations in your models, not your migrations. :)
Was This Post Helpful? 0
  • +
  • -

#3 lakerice   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 27-June 15

Re: Ruby on Rails issue - Migrations Pending error

Posted 18 July 2015 - 11:54 AM

View PostMartyr2, on 17 July 2015 - 09:48 PM, said:

I don't think I have seen associations inside of migrations. Are you sure it said to put them there? Associations typically belong in models. In the directions for your course it is saying put those associations in your Album and Track models... not in the migration. I do know that your create tracks migration has an "end" statement on line 3 that should not be there either.

Try this...

class CreateAlbums < ActiveRecord::Migration
  def change
    create_table :albums do |t|
      t.string :cover
      t.string :title
      t.string :artist
      t.belongs_to :album
      t.timestamps
    end
  end
end



..and

class CreateTracks < ActiveRecord::Migration
  def change
    create_table :tracks do |t|
      t.string :name
      t.string :minutes
      t.references :album
      t.belongs_to :album
      t.timestamps
    end
  end
end



And again put your associations in your models, not your migrations. :)/>


Thanks it worked!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1