On Apr 4, 9:36 am, mike jones <[email protected]> wrote: > Hey > > I have had a problem with my migration scripts (using 2.12.0 and > 2.11.0) and I tracked it down to when I execute alter table commands > using sql then run try to add a foreign key to and existing table. I > get an exception like... > > Mysql::Error Can't create table 'test.#sql-90_15d' (errno: 150) > > Here is an example script that will reproduce the behavior (it just > assumes you have a mysql database called test) > > require "rubygems" > require "sequel" > > DB = Sequel.mysql(:host => "localhost", :user => "root", :database => > "test") > > DB.create_table(:users) do > primary_key :id > varchar :email, :size => 255, :null => false, :index => true > varchar :crypted_password, :size => 40, :null => false > varchar :salt, :size => 40, :null => false > end > DB.execute 'ALTER TABLE users ENGINE = InnoDB' > DB.execute 'ALTER TABLE users DEFAULT CHARACTER SET utf8' > > DB.create_table(:cards) do > primary_key :id > end > DB.execute 'ALTER TABLE cards ENGINE = InnoDB' > DB.execute 'ALTER TABLE cards DEFAULT CHARACTER SET utf8' > > DB.alter_table(:cards) do > add_foreign_key :user_id, :users > end
Could you try running this migration script with an SQL logger to see what SQL is being produced? I can't see any problems with your code just by looking at it. Also, support was added to allow options to create_table in a recent release. So you could pass in the :engine and :charset option to create_table, instead of using the ALTER TABLE sql manually. Jeremy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en -~----------~----~----~----~------~----~------~--~---
