mysql database error
I installed stringer on local dev machine, however rake db:migrate gives me the following errors.
== AddUniqueConstraints: migrating ===========================================
-- add_index(:stories, [:permalink, :feed_id], {:unique=>true})
D, [2013-05-16T06:44:16.916712 #4818] DEBUG -- : Mysql2::Error: BLOB/TEXT column 'permalink' used in key specification without a key length: CREATE UNIQUE INDEX index_stories_on_permalink_and_feed_id ON stories (permalink, feed_id)
rake aborted!
An error has occurred, all later migrations canceled:
Mysql2::Error: BLOB/TEXT column 'permalink' used in key specification without a key length: CREATE UNIQUE INDEX index_stories_on_permalink_and_feed_id ON stories (permalink, feed_id)/Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:in query' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:inblock in execute'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:280:in block in log' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb:20:ininstrument'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:275:in log' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:243:inexecute'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/connection_adapters/mysql2_adapter.rb:211:in execute' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/schema_statements.rb:352:inadd_index'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/migration.rb:466:in block in method_missing' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/migration.rb:438:inblock in say_with_time'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/migration.rb:438:in say_with_time' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/migration.rb:458:inmethod_missing'
/Users/Deepak/apps/reader/db/migrate/20130509131045_add_unique_constraints.rb:3:in change' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/migration.rb:407:inblock (2 levels) in migrate'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/migration.rb:407:in block in migrate' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_pool.rb:129:inwith_connection'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/migration.rb:389:in migrate' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/migration.rb:528:inmigrate'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/migration.rb:720:in block (2 levels) in migrate' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/migration.rb:777:incall'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/migration.rb:777:in ddl_transaction' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/migration.rb:719:inblock in migrate'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/migration.rb:700:in each' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/migration.rb:700:inmigrate'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/migration.rb:570:in up' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.12/lib/active_record/migration.rb:551:inmigrate'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/sinatra-activerecord-1.2.2/lib/sinatra/activerecord/rake.rb:33:in block in migrate' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/sinatra-activerecord-1.2.2/lib/sinatra/activerecord/rake.rb:53:insilence_activerecord'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/sinatra-activerecord-1.2.2/lib/sinatra/activerecord/rake.rb:31:in migrate' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195/gems/sinatra-activerecord-1.2.2/lib/sinatra/activerecord/tasks.rake:11:inblock (2 levels) in <top (required)>'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.0.4/lib/rake/task.rb:246:in call' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.0.4/lib/rake/task.rb:246:inblock in execute'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.0.4/lib/rake/task.rb:241:in each' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.0.4/lib/rake/task.rb:241:inexecute'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.0.4/lib/rake/task.rb:184:in block in invoke_with_call_chain' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.0.4/lib/rake/task.rb:177:ininvoke_with_call_chain'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.0.4/lib/rake/task.rb:170:in invoke' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.0.4/lib/rake/application.rb:143:ininvoke_task'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.0.4/lib/rake/application.rb:101:in block (2 levels) in top_level' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.0.4/lib/rake/application.rb:101:ineach'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.0.4/lib/rake/application.rb:101:in block in top_level' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.0.4/lib/rake/application.rb:110:inrun_with_threads'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.0.4/lib/rake/application.rb:95:in top_level' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.0.4/lib/rake/application.rb:73:inblock in run'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.0.4/lib/rake/application.rb:160:in standard_exception_handling' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.0.4/lib/rake/application.rb:70:inrun'
/Users/Deepak/.rvm/gems/ruby-2.0.0-p195/bin/ruby_noexec_wrapper:14:in eval' /Users/Deepak/.rvm/gems/ruby-2.0.0-p195/bin/ruby_noexec_wrapper:14:in
Does it work if you change this line?https://github.com/swanson/stringer/blob/master/db/migrate/20130509131045_add_unique_constraints.rb#L3 to
add_index :stories, [:permalink, :feed_id], unique: true, length: 1000
Hi,
No still it does not work. The error is as below
== AddUniqueConstraints: migrating ===========================================
-- add_index(:stories, [:permalink, :feed_id], {:unique=>true, :length=>1000})
D, [2013-05-16T07:32:23.190912 #5280] DEBUG -- : Mysql2::Error: Specified key was too long; max key length is 767 bytes: CREATE UNIQUE INDEX index_stories_on_permalink_and_feed_id ON stories (permalink(1000), feed_id(1000))
rake aborted!
An error has occurred, all later migrations canceled:
I tried with length: 100, then the error was as below
== AddUniqueConstraints: migrating ===========================================
-- add_index(:stories, [:permalink, :feed_id], {:unique=>true, :length=>100})
D, [2013-05-16T07:33:54.615380 #5282] DEBUG -- : Mysql2::Error: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys: CREATE UNIQUE INDEX index_stories_on_permalink_and_feed_id ON stories (permalink(100), feed_id(100))
rake aborted!
You can comment out that line, run the migrations and probably be fine. Technically only postgres is supported, but you don't need this index for the app to work. Uniqueness is checked at the app level as well, enforcing it at the DB level is just an extra protection.
Alternatively, you can try:
add_index :stories, [:permalink, :feed_id], unique: true, length: { permalink: 767 }
though I'm not sure if that will work either.
@brahmadpk any update on this?
With the line commented out, the migrations work fine.
I dont know if not having the index breaks any other feature in the app.
It shouldn't. If you notice anything else, let me know