Reputation: 13
I am getting an error while migrating a database. The error is:
PG::UndefinedColumn: ERROR: column roles.deleted_at does not exist
LINE 1: SELECT "roles".* FROM "roles" WHERE ("roles"."deleted_at" I...
^
: SELECT "roles".* FROM "roles" WHERE ("roles"."deleted_at" IS NULL)
Here is my part of schema.rb:
create_table "roles", :force => true do |t|
t.string "name"
t.string "title"
t.integer "resource_id"
t.string "resource_type"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "deleted_at"
end
I tried to make:
rails generate migration AddDeletedAtToRoles deleted_at
But it did not help.
Upvotes: 1
Views: 1517
Reputation: 1658
Sometimes what I do in order to get rid of these inconsistent database states is, if it's a simple fix, go into the actual database and fix manually whatever seems to be the problem in order to get migrations going again.
In your case it seems like you are missing the deleted_at
column in the roles table. So what you could do is create the column yourself. In order to do that in Postgres you would need to do something like:
psql your_database_name
once you are in there Alter your roles
table and add the column you are missing using the following command.ALTER TABLE roles ADD COLUMN deleted_at date;
Hope that helps.
Upvotes: 0
Reputation: 7532
If a column exists in your schema but a migration is failing because it's not found, you may be in an inconsistent database state (i.e. your database's current schema is not in line with schema.rb, nor can you migrate as the migrations are incompatible with your current state). There are lots of ways to get into that state, but in any case, your best bet is to wipe your database clean and migrate again:
bin/rake db:reset db:migrate
If that doesn't work, you have more serious issues. If this is a fairly new app, bin/rake db:drop db:create db:migrate
may be able to help; otherwise, you've got some debugging and sleuthing to do.
Upvotes: 1