-
-
Notifications
You must be signed in to change notification settings - Fork 589
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
friendly_id Error when migrating with history plugin #299
Comments
Looks like the slugs table doesn't exist? |
@parndt you are correct, but shouldn't it be using the friendly_id_slugs table? I'm using gem version 4.0.7 schema.rb: create_table "friendly_id_slugs", :force => true do |t|
t.string "slug", :null => false
t.integer "sluggable_id", :null => false
t.string "sluggable_type", :limit => 40
t.datetime "created_at"
end
add_index "friendly_id_slugs", ["slug", "sluggable_type"], :name => "index_friendly_id_slugs_on_slug_and_sluggable_type", :unique => true
add_index "friendly_id_slugs", ["sluggable_id"], :name => "index_friendly_id_slugs_on_sluggable_id"
add_index "friendly_id_slugs", ["sluggable_type"], :name => "index_friendly_id_slugs_on_sluggable_type" |
Yes, according to this documentation it should be friendly_id_slugs https://github.com/norman/friendly_id/blob/master/lib/friendly_id/history.rb Did you follow those instructions exactly? https://github.com/norman/friendly_id/blob/master/lib/friendly_id/slug.rb This indicates the table_name is being set correctly.. Can you go into the console and run: FriendlyId::Slug.table_name and report the result please? |
Not sure why it won't find it when I first bring it up and why I need to attempt to access another model first.. Loading development environment (Rails 3.2.5)
irb(main):001:0> FriendlyId::Slug.table_name
NameError: uninitialized constant FriendlyId::Slug
from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing_from_s3_library'
from (irb):1
from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.5/lib/rails/commands/console.rb:47:in `start'
from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.5/lib/rails/commands/console.rb:8:in `start'
from /usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.5/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
irb(main):002:0> Address.first
Address Load (1.1ms) SELECT "addresses".* FROM "addresses" LIMIT 1
=> #<Address id: 473...>
irb(main):003:0> FriendlyId::Slug.table_name
=> "friendly_id_slugs" |
I'm guessing that the FriendlyId library isn't loaded until that point. :-) OK so you're getting the right table_name which makes this stranger because the history code just asks Slug all the details: https://github.com/norman/friendly_id/blob/master/lib/friendly_id/history.rb#L66-L67 |
In the migration if I try just outputting FriendlyId::Slug.table_name and I get the following: uninitialized constant FriendlyId::Slug not sure if that is helpful or not |
what if, in the migration, you call: require 'friendly_id' |
An error has occurred, this and all later migrations canceled:
PG::Error: ERROR: current transaction is aborted, commands ignored until end of transaction block
: SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"addresses"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum with this in the log
|
Strange. I'm out of ideas and will have to escalate to @norman :-) |
Not sure whats going on but when history is included it appears that the FriendlyId::Slug is not being loaded. Including Perhaps requiring it in the migration is too late? |
Weeeeird |
Without this change, FriendlyId::Slug is not accessible from migrations unless friendly_id/slug is explicitly required. This should resolve issue #299.
@malomalo Thanks for the detailed report and followup, and sorry for the slow response. I was able to reproduce your problem locally, and I've just now pushed a change which should fix it. Can you let me know if it works for you? |
@norman sorry for the late reply, I'll try and check it out this weekend |
Closing this since it was fixed and already released a while ago. |
I am having the same issues |
I get the following when Trying to call any model or reseting the column information on a model:
I've narrowed it down to when the history plugin is used. The logs show the following query that errors in Postgres:
Been trying all day to get to the bottom of this, but no success yet.
The text was updated successfully, but these errors were encountered: