postgresql,ADD CONSTRAINT错误

时间:2016-05-14 15:10:40

标签: ruby-on-rails postgresql

rails db:migrate 给出错误:= 类型" email_must_be_company_email"不存在..

迁移文件是............

class AddEmailConstraintToUsers < ActiveRecord::Migration 
  def up
     execute %{
       ALTER TABLE users
       ADD CONTRAINT ***email_must_be_company_email***
       CHECK ( email ~* '^[^@]+@example\\.com'  )
      }  
  end  

  def down
    execute %{
      ALTER TABLE users
      DROP CONTRAINT ***email_must_be_company_email***
    }
 end
end

1 个答案:

答案 0 :(得分:0)

您已将CONSTRAINT一词拼错为CONTRAINT,因此postgres将其解释为列名,并将email_must_be_company_email解释为列类型。