1

After running:

rails g model category

and updating my migration to show:

class CreateCategories < ActiveRecord::Migration 
  def change create_table :categories do |t| 
    t.string :name t.text :description
    t.timestamps null: false
   end
   end
end

Then running:

rails g model albumcategories

and updating my migration to show:

class CreateAlbumCategories < ActiveRecord::Migration
def change
    create_table :album_categories do |t|
        t.references :album, index: true, foreign_key: true
        t.references :category, index: true, foreign_key: true

        t.timestamps null: false
    end
    end
end

I ran rake db:migrate I got the following output:

    20160627163454 CreateCategories: migrating =================================
    -- create_table(:categories)
   -> 0.0768s
== 20160627163454 CreateCategories: migrated (0.0769s) ========================

== 20160627163757 CreateAlbumCategories: migrating ============================
-- create_table(:album_categories)
   -> 0.1252s
== 20160627163757 CreateAlbumCategories: migrated (0.1253s) ===================

But neither of these new tables show up in my Schema. I have tested them both in the console and I am able to connect to them. i.e. @album.categories.count gives me an output of "0" Does anyone know what is going on here? It seems odd that my schema wouldn't update, but the tables would still be available in the console. Databases have been troubling to me in the past, so I don't want to move too far forward just to find out I need to redo a lot of work. Any insight would be appreciated.

Lenocam
  • 331
  • 2
  • 17
  • Possible duplicate of [Rails: I update migration file then run db:migrate, but my schema isn't updating](http://stackoverflow.com/questions/1416600/rails-i-update-migration-file-then-run-dbmigrate-but-my-schema-isnt-updating) – vich Jun 28 '16 at 17:11
  • I did see this before and ran the commands it suggested, db:migrate:redo, db:rollback, etc.. and then re-ran these migrations. They still don't show up in my Schema. Something interesting that came out of redoing those again is that I hit a point where it wouldn't let me rollback any further '== 20160615222357 RefilePostgresMigrationTo130: reverting ===================== rake aborted! StandardError: An error has occurred, this and all later migrations canceled: ActiveRecord::IrreversibleMigration ' – Lenocam Jun 28 '16 at 17:37
  • Are these migrations recorded in your `schema_migrations` table? Can you post what's in the table? – Jake Wood Jun 28 '16 at 17:57
  • Before I post a file, because it looks like pretty large file, would the "schema_migrations table" be in the db/strucure.sql file, just schema.rb or some other place? – Lenocam Jun 28 '16 at 18:40
  • @Lenocam In general, you want to avoid reversible migrations, mostly to avoid dealing with issues like this. Beyond that, your schema "version" might have gotten out of sync with your migration filename timestamps. I've had issues in the past with my schema file not updating certain migration files due to having earlier timestamps in the filename. – vich Jun 28 '16 at 18:58
  • @mmichael There is only one reversible migration in my long list of migrations and it was created for me when I updated the "Refile_postgres" gem. The down, is 'raise ActiveRecord::IrreversibleMigration'. So am i stuck with what I have? – Lenocam Jun 28 '16 at 19:17
  • @JakeWood I'm still having issues with this, could you be more specific about where I would find the info you'd like me to provide? I assume it isn't the schema.rb file... – Lenocam Jun 29 '16 at 18:35

1 Answers1

0

Try using this command: rake db:schema:load

Shreya
  • 63
  • 6