1

I am in a world of mess. I had some issues with the mailboxer gem and the tables it created in my schema, so i commented the offending attributes and reset my database. Nothing changed when I ran db:migrate, so I dropped the table, created it anew and reran the migration. The schema has not updated to reflect the attributes which had been commented out. Any ideas as to why? I now have an error message when trying to rake db:migrate which aborts and says that:

PG::UndefinedTable: ERROR:  relation "roles" does not exist : ALTER TABLE "roles" DROP "user_id"

My schema has a roles table which includes the following attributes:

create_table "roles", force: true do |t|
t.string   "name"
t.datetime "created_at"
t.datetime "updated_at"
t.integer  "user_id"
end

I have a migration in my file which is intended to remove the user_id:

class Removeuidfromrole < ActiveRecord::Migration
  def change

    remove_column :roles, :user_id, :integer

  end
end

I have no idea why it is aborting with an error telling me to remove the user id, when I have a migration to do just that. Further, why doesn't the schema update to reflect the recreated db?

Nikola
  • 817
  • 13
  • 19
Mel
  • 2,481
  • 26
  • 113
  • 273
  • 2
    Is this in your development environment or production environment? If development, delete all database tables, including `schema_migrations`, and run the migrations again. If production, then you have quite a mess to clean up. :( – Chris Peters May 18 '14 at 04:55
  • Please check this answer http://stackoverflow.com/questions/3815447/does-rake-dbschemadump-recreate-schema-rb-from-migrations-or-the-database-itse i.e. try recreating the schema from db first. – amitamb May 18 '14 at 04:58
  • I ran reset as well as drop. Please can you tell me what are the commands to delete all database tables including scheme migrations? – Mel May 18 '14 at 04:58
  • Thanks amitamb. I managed to match the schema to the migrations with db:migrate redo – Mel May 18 '14 at 04:59
  • did you get this fixed? i get this error all the time. all you have to do is delete `Removeuidfromrole` and run `rake:db:migrate` – Wally Ali May 18 '14 at 05:33
  • Thanks Wali. It is sorted now. But strangely, the whole roles table was deleted when i did rake db:migrate redo. I didn't have a migration removing it but I recreated it without the id and it's fine now. Thanks just the same! – Mel May 18 '14 at 05:48
  • Try rake db:migrate:reset and let me know what happens – mrudult May 18 '14 at 09:05
  • Thans mrudult. reset was the first step i tried before posting my question. It it helps others, I resolved my problem by drop/create/migrate redo. Note that rake db:migrate didn't work to update the schema. you need migrate redo. – Mel May 18 '14 at 12:28

0 Answers0