# Nil object error for "rake db:migrate"

**URL:** <https://www.ruby-forum.com/t/nil-object-error-for-rake-db-migrate/128522>\
**Category:** Rails\
**Created:** [February 8, 2008, 12:21pm UTC](https://www.ruby-forum.com/t/nil-object-error-for-rake-db-migrate/128522 "2008-02-08T12:21:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [February 8, 2008, 12:21pm UTC](https://www.ruby-forum.com/t/nil-object-error-for-rake-db-migrate/128522/1 "2008-02-08T12:21:26Z")

</div>

I’m going to start removing relationships and data-entry during the  
migration, but where’s this nil object coming from?

Is it because of the relationship, or is there something wrong with the  
way data is entered during the migration? I’m not seeing what would  
introduce the nil object ☹

thufir@arrakis ~/goodfellow-tool $  
thufir@arrakis ~/goodfellow-tool $  
thufir@arrakis ~/goodfellow-tool $ sqlite3 db/development.sqlite3  
SQLite version 3.4.1  
Enter “.help” for instructions  
sqlite\> .schema  
CREATE TABLE schema\_info (version integer);  
sqlite\> .quit  
thufir@arrakis ~/goodfellow-tool $  
thufir@arrakis ~/goodfellow-tool $ rake db:migrate VERSION=0  
(in /home/thufir/goodfellow-tool)  
thufir@arrakis ~/goodfellow-tool $  
thufir@arrakis ~/goodfellow-tool $ rake db:migrate  
(in /home/thufir/goodfellow-tool)  
rake aborted!  
You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.-@

(See full trace by running task with --trace)  
thufir@arrakis ~/goodfellow-tool $  
thufir@arrakis ~/goodfellow-tool $ cat db/migrate/001\_calls.rb  
-class Calls \< ActiveRecord::Migration  
def self.up  
create\_table “calls” do |call|  
call.column “login”, :string  
call.column “start”, :datetime  
call.column “comment”, :string  
end

```
            Call.create :login => "0123",
                            :start => "Mon Jan 01 16:00:00

```

-0800 2007",  
:comment =\> “start work”

```
            Call.create :login => "0123",
                            :start => "Mon Jan 01 17:00:00

```

-0800 2007",  
:comment =\> “call received”

```
            Call.create :login => "0123",
                            :start => "Mon Jan 01 19:00:00

```

-0800 2007",  
:comment =\> “call ended”

```
            Call.create :login => "0123",
                            :start => "Mon Jan 01 22:00:00

```

-0800 2007",  
:comment =\> “end work”

```
            Call.create :login => "1234",
                            :start => "Mon Jan 01 22:00:00

```

-0800 2007",  
:comment =\> “start”  
end

```
    def self.down
            drop_table "calls"
    end

```

end  
thufir@arrakis ~/goodfellow-tool $  
thufir@arrakis ~/goodfellow-tool $ cat db/migrate/002\_employees.rb  
class Employees \< ActiveRecord::Migration  
def self.up  
create\_table “employees” do |employee|  
employee.column “code”, :string  
employee.column “first\_name”, :string  
employee.column “last\_name”, :string  
end

```
            Employee.create :code =>

```

“abc123”,  
:first\_name =\>  
“John”,  
:last\_name =\> “Doe”

```
            Employee.create :code =>

```

“abc321”,  
:first\_name =\>  
“Jane”,  
:last\_name =\> “Doe”  
end

```
    def self.down
            drop_table "employees"
    end

```

end  
thufir@arrakis ~/goodfellow-tool $  
thufir@arrakis ~/goodfellow-tool $ cat db/migrate/003\_logins.rb  
class Logins \< ActiveRecord::Migration  
def self.up  
create\_table “logins” do |login|  
login.column “login”, :string  
login.column “employee\_id”, :string  
end

```
            Login.create :login => "0123",
                                    :employee_id => "abc123"
    end

    def self.down
            drop_table "logins"
    end

```

end  
thufir@arrakis ~/goodfellow-tool $  
thufir@arrakis ~/goodfellow-tool $ cat app/models/call.rb  
class Call \< ActiveRecord::Base  
belongs\_to :login  
end  
thufir@arrakis ~/goodfellow-tool $  
thufir@arrakis ~/goodfellow-tool $ cat app/models/login.rb  
class Login \< ActiveRecord::Base  
belongs\_to :employee  
has\_many :call  
end  
thufir@arrakis ~/goodfellow-tool $  
thufir@arrakis ~/goodfellow-tool $ cat app/models/employee.rb  
class Employee \< ActiveRecord::Base  
has\_many :login  
end  
thufir@arrakis ~/goodfellow-tool $

thanks,

Thufir
