Re: [Rails] why is migration failing?
On 10-11-07 05:44 AM, Michael Pavling wrote:
> On 7 November 2010 10:37, Rajinder Yadav<devguy.ca@gmail.com> wrote:
>> I get the following when I run rake db:migrate, which doesn't make sense
>> because nowhere am i specifing a default value!
>>
>> SQLite3::SQLException: Cannot add a NOT NULL column with default value NULL:
>> ALTER TABLE "ticke
>> ts" ADD "location" varchar(30) NOT NULL
>
> You're kidding right? That doesn't make sense?!
>
> You're adding a column with no default value (so, that's a default
> value of "NULL") to a table which presumably already has data in it.
> And you're saying that the column should *not* allow NULL, even though
> you don't specify a default value. So the existing columns will all
> have NULL as the value for the field you just created, except you tell
> the DB that NULL is not allowed - so there's an exception.
>
> Seems to make sense to me.
>
> Either:
> delete all the existing data (assuming it's test/development data)
> before running the migration
> or
> specify a default value for the field...
>
I don't have any existing data. I do
rake db:migrate VERSION=0
rake db:migrate
What do you mean? how is that any different from the following which
works fine!
class CreateTickets < ActiveRecord::Migration
def self.up
create_table :tickets do |t|
t.string :location, :null => false, :limit => 30
t.timestamps
end
end
def self.down
drop_table :tickets
end
end
--
Kind Regards,
Rajinder Yadav | DevMentor.org | Do Good! ~ Share Freely
GNU/Linux: 2.6.35-22-generic
Kubuntu x86_64 10.10 | KDE 4.5.1
Ruby 1.9.2p0 | Rails 3.0.1
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home