CommentにPostのuuidに対する外部キー制約をつけたいのですが、うまくいきません。
環境は下記となります。
rails 5.1.4
mysql2 0.4.10
■Postモデルのマイグレーション class CreatePosts < ActiveRecord::Migration[5.1] def change create_table :posts, :id => false, :primary_key => "uuid" do |t| t.string :uuid, limit: 36, null: false t.text :content t.timestamps end execute 'ALTER TABLE posts ADD PRIMARY KEY (uuid);' end end
■Commentモデルのマイグレーション class CreateComments < ActiveRecord::Migration[5.1] def change create_table :comments do |t| t.string :content t.string :ip t.string :post_uuid t.timestamps end add_foreign_key :comments, :posts, column: :post_uuid end end
データベースの作成まではできるのですが、undefined method `sql_type' for nil:NilClassというエラーが出て先に進みません。
どなたかわかるかたご教授願います。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。