我在我的开发数据库(sqlite3)中填充了少量测试数据的表'invoices'。无法扭转貌似简单的rails迁移 - 获取“altered_table.column可能不是NULL”错误
我想一列“INVOICE_NUMBER”添加到它和设置迁移像这样:
class AddInvoiceNumberColumnToInvoices < ActiveRecord::Migration
def self.up
add_column :invoices, :invoice_number, :integer
end
def self.down
remove_column :invoices, :invoice_number
end
end
我跑rake db:migrate
,它似乎迁移就好了。但是,当我试图通过ActiveRecord访问此列时,它似乎并不存在。我决定撤消这个迁移,然后再次尝试(不知道我要去试试,但我想我会开始撤销它)与rake db:migrate VERSION='whatever_the_migration_before_this_one_was_called'
。此错误消息失败
== AddInvoiceNumberColumnToInvoices: reverting ===============================
-- remove_column(:invoices, :invoice_number)
rake aborted!
An error has occurred, this and all later migrations canceled:
altered_invoices.invoice_number may not be NULL
我找不到此错误的任何文档。有人能够解释我做错了什么,更重要的是我该如何解决这个问题?
唉,我有同样的问题,将这样移除目前的所有数据库中的记录? – 2013-01-02 18:30:09
它不应该这样做。 SQLite数据库存储在不应受修改gem或sqlite本身影响的单独文件中。 – brad 2013-01-03 01:39:30