Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add / Edit enum #5

Closed
drhenner opened this issue Sep 25, 2011 · 1 comment
Closed

Add / Edit enum #5

drhenner opened this issue Sep 25, 2011 · 1 comment

Comments

@drhenner
Copy link

Is there a way to add enum's to existing tables?

Also If I need to add a new value to the enum what is the syntax.

I want to change an enum column from
From
status ('pending', 'active')
To
status ('pending', 'active', 'canceled')


and can I do something like this?

add_column :status, :enum, :limit => [:casual, :formal, :wild, :sports, :neutral, :colorful]
@electronick
Copy link
Owner

Yep, if you need to add new values and leave all old values it will work without any problems, so if you have
status ('pending', 'active')
and want to have
status ('pending', 'active', 'canceled')
just make a migration like


But if some of old values are going to be removed you should take care of objects with such values manually. For example if you need to rename some value you should do like this:

execute('update tasks set status="active" where status="actice"')
change_column :tasks, :status, :enum, :limit => [:pending, :active]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants