This project is archived and is in readonly mode.
Rails 3: :null => false, tests and ActiveRecord::StatementInvalid: SQLite3::SQLException XXXXX may not be NULL
Reported by Marc Love | February 20th, 2010 @ 10:43 AM
Okay, long description here, but follow me...
Create a new Rails project
rails testapp
cd testapp
Create your first resource
rails generate resource User
Create a migration that sets :null => false on a field
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :email, :null => false
t.timestamps
end
end
def self.down
drop_table :users
end
end
Run your migration
rake db:migrate
Try to run your default "test truth" tests
rake test:units
This gives the following error message:
Loaded suite /Users/marc/.bundle/ruby/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
E
Finished in 0.066302 seconds.
1) Error:
test_the_truth(UserTest):
ActiveRecord::StatementInvalid: SQLite3::SQLException: users.email may not be NULL: INSERT INTO "users" ("created_at", "updated_at", "id") VALUES ('2010-02-20 10:39:59', '2010-02-20 10:39:59', 298486374)
1 tests, 0 assertions, 0 failures, 1 errors
rake aborted!
Command failed with status (1): [/usr/local/bin/ruby -I"lib:test" "/Users/m...]
The same error pops up for any actual tests you create. The hangup seems to be any columns set to :null => false
Comments and changes to this ticket
-
José Valim February 23rd, 2010 @ 09:30 PM
- State changed from new to invalid
Yes, this is expected. You have to configure your fixtures or given the proper args to User.create.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>