Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
change_column :posts, :ID, :string, :null => false
我在 add_column 之后使用了它,但是当我将值保留为空时,它不会显示任何错误。为什么以及我能做些什么来捕获错误?
您应该在模型中使用验证:
class Post < ActiveRecord::Base validates :column_name, presence: true end
最好不要使用 :id 来存储一些字符串。此列名称在 Rails 中保留。