我正在 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
宝石)。这是迁移示例 - 关键部分:
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
,但它正确吗?