我创建了一个带有列定义的模型
create_table :admin_authentication_tokens do |t|
t.integer :authentication_ttl
end
Run Code Online (Sandbox Code Playgroud)
现在我想让它authentication_ttl不可空.我试过这个迁移
change_column :admin_authentication_tokens, :authentication_ttl, :integer, null: false, default: 0
Run Code Online (Sandbox Code Playgroud)
但得到一个错误,
PG::NotNullViolation: ERROR: column "authentication_ttl" contains null values
我明白错误意味着什么,但我不想手动迁移模型.那么请给我一种方法来迁移模型与迁移文件.