【发布时间】:2012-04-09 10:45:09
【问题描述】:
我正在 localhost 上开发我的应用程序(Rails 3.2、PostgreSQL 9.1),在那里一切正常,所以我决定将应用程序部署到 Heroku 的生产环境中。
成功部署应用后,我尝试创建新项目并收到以下错误消息:
ActiveRecord::StatementInvalid (PG::Error: ERROR: null value in column "persistence_token" violates not-null constraint
关于桌子Users(使用Authlogic gem)。这是迁移示例 - 关键部分:
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :name, :null => false
t.string :email, :null => false
t.string :crypted_password, :default => nil, :null => true
t.string :password_salt, :default => nil, :null => true
t.string :email, :default => nil, :null => true
t.string :persistence_token, :null => false
t.string :single_access_token, :null => false
t.string :perishable_token, :null => false
t.datetime :last_request_at
t.datetime :current_login_at
t.datetime :last_login_at
t.string :current_login_ip
t.string :last_login_ip
t.timestamps
end
end
end
什么可能导致这个问题?我的意思是,我在迁移中看到的是规则 :null => false 并且错误消息说明了保存到此列中的空值,但是如何在 localhost 上很好地工作而在 Heroku 上却不行?
而且,我该如何解决这个问题?我的第一个想法是创建一个新的迁移,在那里我为该列设置:null => true,但它是否正确?
【问题讨论】:
-
设置
:null => true只允许列中的null值,隐藏原始问题并打开一罐蠕虫。
标签: validation heroku authlogic ruby-on-rails-3.2 postgresql-9.1