Skip to content

generated db/schema.rb can't be loaded using rake db:schema:load (Rails 3.2.1) #5099

Closed
jana4u opened this Issue Feb 20, 2012 · 3 comments

2 participants

@jana4u
jana4u commented Feb 20, 2012

Everything worked fine in Rails 3.1.3, but after upgrading to 3.2.1, it is not possible to load DB schema anymore.

Problem is caused by index created using execute in migration:

execute "CREATE UNIQUE INDEX index_slugs_on_name_and_sluggable_type_and_scope_and_sequence ON slugs (name(250), sluggable_type, scope, sequence)"

This line is added to db/schema.rb (both Rails 3.1.3 and 3.2.1 generate the same):

add_index "slugs", ["name", "sluggable_type", "scope", "sequence"], :name => "index_slugs_on_name_and_sluggable_type_and_scope_and_sequence", :unique => true, :length => {"name"=>250, "sluggable_type"=>nil, "scope"=>nil, "sequence"=>nil}

But when you run rake db:schema:load, invalid SQL is generated in Rails 3.2.1 and exception raised:

-- create_table("slugs", {:force=>true})
   -> 0.4759s
-- add_index("slugs", ["name", "sluggable_type", "scope", "sequence"], {:name=>"index_slugs_on_name_and_sluggable_type_and_scope_and_sequence", :unique=>true, :length=>{"name"=>250, "sluggable_type"=>nil, "scope"=>nil, "sequence"=>nil}})
rake aborted!
Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '), `scope`(), `sequence`())' at line 1: CREATE UNIQUE INDEX `index_slugs_on_name_and_sluggable_type_and_scope_and_sequence` ON `slugs` (`name`(250), `sluggable_type`(), `scope`(), `sequence`())

I made new Rails 3.2.1 app, added migration and generated db/schema.rb - see https://github.com/jana4u/test_add_index

I am running it on ruby 1.9.3p0.

@kennyj
kennyj commented Feb 20, 2012

@jana4u
I think this issue is same to #4651.
This pull request was merged to master and 3-2-stable.

@kennyj
kennyj commented Feb 22, 2012

ping @jana4u
Do you have any news ?

If this issue was merged already, we want to close this one :-)

@jana4u
jana4u commented Feb 22, 2012

Using edge rails (gem 'rails', :git => 'git://github.com/rails/rails.git') it works. I hope it will be released in gem version soon.

@jana4u jana4u closed this Feb 22, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.