Reputation: 127
I don't know why I can't add the column "Admin" to my Users table. I run in the terminal "rails g migration AddAdminToUsers admin:boolean" and it creates the file in db/migrate. When I run rake db:migrate I get the following error:
"PG::DuplicateColumn: ERROR: column "admin" of relation "users" already exists"
In the schema.rb file I don't see that there is a column for admin. When I run rake db:migrate:status I can see the status for "Add admin to users" is "down" while everything else is "up". I can resolve the issue by typing rails db:migrate:reset but then I lose the data of my Users along with other data.
How can I add the admin column to my Users table?
Upvotes: 1
Views: 338
Reputation: 34338
"PG::DuplicateColumn: ERROR: column "admin" of relation "users" already exists"
The error message is very clear. You already have an admin
column in your users
table. You have to remove that before you can add admin
column to your users
table.
To remove the already existing admin
column, generate a migration:
rails g migration RemoveAdminFromUsers admin:boolean
then run the migration to remove the admin
from users
:
rake db:migrate
Now you can add it back again:
rails g migration AddAdminToUsers admin:boolean
Upvotes: 1