On Feb 8, 2:09 am, Clive Crous <clive.cr...@gmail.com> wrote:
> Hi,
>
> I think this is a bug, but I'm not too familiar with MySQL (I mostly
> use Postgresql). I'm quite unable to use foreign keys in MySQL because
> I get a syntax error when I run the migrations. I've created a
> stripped down minimal example on how to reproduce this. I tested
> against the current GitHub source and it's doing this currently.
>
> Create a MySQL database and run the following two migrations:
>
> 001_authors.rb:
>
> class CreateAuthors < Sequel::Migration
>   def up
>     create_table :authors, :engine => 'InnoDB' do
>       primary_key :id
>       varchar :name
>     end
>   end
> end
>
> 002_posts.rb:
>
> class CreatePosts < Sequel::Migration
>   def up
>     create_table :posts, :engine => 'InnoDB' do
>       foreign_key :author_id, :table => :authors
>       text :content
>     end
>   end
> end

Looks like if the foreign key wasn't the last item in the generator,
it generated SQL that worked fine with MyISAM, but that InnoDB didn't
like.

Try the diff at http://pastie.org/815005.txt, and make sure to provide
a :key option to foreign_key, since MySQL/InnoDB requires it.
Example:

  class CreatePosts < Sequel::Migration
    def up
      create_table :posts, :engine=>:InnoDB do
        foreign_key :author_id, :authors, :key=>:id
        text :content
      end
    end
  end

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to sequel-t...@googlegroups.com.
To unsubscribe from this group, send email to 
sequel-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to