Unable to reverse seemingly simple rails migration - getting "altered_table.column may not be NULL"
Posted
by brad
on Stack Overflow
See other posts from Stack Overflow
or by brad
Published on 2010-03-22T12:38:48Z
Indexed on
2010/03/22
12:41 UTC
Read the original article
Hit count: 383
I have a table 'invoices' in my development database (sqlite3) populated with a small amount of test data.
I wanted to add a column 'invoice_number' to it and set up a migration like so:
class AddInvoiceNumberColumnToInvoices < ActiveRecord::Migration
def self.up
add_column :invoices, :invoice_number, :integer
end
def self.down
remove_column :invoices, :invoice_number
end
end
I ran rake db:migrate
and it seemed to migrate just fine. However, when I tried to access this column through ActiveRecord it didn't seem to be there. I decided to undo this migration and try again (not sure what I was going to try but I thought I'd start by undoing it) with rake db:migrate VERSION='whatever_the_migration_before_this_one_was_called'
. This failed with the error message
== 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
I can't find any documentation of this error. Is anyone able to explain what I have done wrong, and more importantly how I can fix this?
© Stack Overflow or respective owner