-
Notifications
You must be signed in to change notification settings - Fork 63
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
undefined method 'enum' when migrating #49
Comments
Try adding a require in your environment.rb require "enumerated_attribute" |
Thanks — it hasn't had any effect, though, even when I've put the require directly into the migration in question. I've remembered to restart the rails server as well :) I can create the column as a t.string, but then it's actually created as VARCHAR(255) rather than ENUM, which removes the point of using the gem in the first place — I need to have the field values restricted at the database level, rather than just managed by rails. |
I'm now noticing the "change_table" call you're making. Mine are all create_table calls, within the change method for the migration. Change your migration to be Also, the t.enum creates a column of type varchar(255) and there is no value checking in the database. The value checking is performed in the application later in the gem within rails. |
And if the column already exists and you're simply trying to change the type, I don't think you have to do this. As I mentioned above, the type is still varchar(255) (string) so I think the migration is unnecessary. |
The reason it's not create_table is because this migration is adding a column to an existing table :) The comment about creating as a string was just from looking at an earlier project where I'd successfully used enumerated_attribute, but I was creating the columns as strings in that — though if enumerated_attribute only adds VARCHAR(255) columns anyway, I guess replacing t.enum with t.string will get things working… Thanks for your help! |
Interesting. I've only added columns using this construct: def change Try :enum instead of :string with this construct. |
Afraid not — it gets as far as mysql this time, though:
Looking at the log, that's the entire statement. Obviously, it needs to know the values of the enum, but it's not very DRY to repeat them in the migration and the model. I think I'll stick to a string. |
The gem should have translated that for you. Something is not right with the inclusion of the gem. |
I've just installed enumerated_attribute (using rails 3.2.1) by the standard method of adding it to the Gemfile and running
bundle
. I have the following migrationand the following as models/article.rb:
According to the README, this should work, no?
But I get
undefined method
enum' for #ActiveRecord::ConnectionAdapters::Table:0x007fbc533e87f0` when I try to migrate.Are the docs out of date? I notice that the README still refers to using
rake gems:install
to install the gem, so I'm wondering if the docs no longer reflect reality.The text was updated successfully, but these errors were encountered: