# Can't sign in as admin user (undefined method \`username' for nil:NilClass)

**URL:** <https://meta.discourse.org/t/cant-sign-in-as-admin-user-undefined-method-username-for-nil-nilclass/68169>\
**Category:** Product Support\
**Created:** [August 16, 2017, 5:55pm UTC](https://meta.discourse.org/t/cant-sign-in-as-admin-user-undefined-method-username-for-nil-nilclass/68169 "2017-08-16T17:55:38Z")\
**Posts on this page:** 11\
**Page:** 1

## AI-generated summary

A user reports an issue with logging in as an admin on a Vagrant-based Discourse installation, encountering a 500 error due to an undefined method `username` for nil:NilClass. The logs indicate a missing system user, prompting a suggestion to run `rake db:migrate`. However, this results in a `LoadError` related to the `Version` constant, likely due to a gem or environment issue. Another user notes the same error occurs outside of Vagrant, and a fix is identified in a recent commit [0e656ff](https://github.com/discourse/discourse/commit/0e656ff213d11b0d416927763c284fa98f91aa5b). The original user confirms the fix resolves the issue. The discussion also clarifies that the Vagrant setup is for development, not production, and the user's goal is to modify default templates for local testing. [almone](/t/-/68169/1) [tgxworld](/t/-/68169/2) [almone](/t/-/68169/3) [tgxworld](/t/-/68169/4) [almone](/t/-/68169/5) [tgxworld](/t/-/68169/6) [almone](/t/-/68169/7) [tgxworld](/t/-/68169/8) [tgxworld](/t/-/68169/9) [almone](/t/-/68169/10)

<div class="post-metadata">

**Author:** ![almone](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/almone/32/120777_2.png) [@almone](https://meta.discourse.org/u/almone)\
**Post date:** [August 16, 2017, 5:55pm UTC](https://meta.discourse.org/t/cant-sign-in-as-admin-user-undefined-method-username-for-nil-nilclass/68169/1 "2017-08-16T17:55:38Z")

</div>

I’m having an issue with logging in as admin user.  
I made a clean Vagrant install according to [this guide](https://github.com/discourse/discourse/blob/master/docs/VAGRANT.md).  
Now when I try to log in I’m getting 500 Internal Server Error.

Here are log records:

```
I, [2017-08-16T13:50:13.258735 #14047] INFO -- : Started GET "/" for 10.0.2.2 at 2017-08-16 13:50:13 -0400
D, [2017-08-16T13:50:14.494951 #14047] DEBUG -- : UserAuthToken Load (1.5ms) SELECT "user_auth_tokens".* FROM "user_auth_tokens" WHERE ((auth_token = 'St0sllamsnLV2NjCPEschUDeDzQ=' OR
                          prev_auth_token = 'St0sllamsnLV2NjCPEschUDeDzQ=' OR
                          (auth_token = '4716df97e4a99a37b3d9b8a8f34af626' AND legacy)) AND rotated_at > '2017-06-17 17:50:14.492802') LIMIT 1
D, [2017-08-16T13:50:14.505749 #14047] DEBUG -- : User Load (2.7ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1 [["id", 1]]
I, [2017-08-16T13:50:14.510414 #14047] INFO -- : Processing by ListController#latest as HTML
D, [2017-08-16T13:50:14.527868 #14047] DEBUG -- : UserOption Load (1.0ms) SELECT "user_options".* FROM "user_options" WHERE "user_options"."user_id" = 1 LIMIT 1 [["user_id", 1]]
D, [2017-08-16T13:50:14.534377 #14047] DEBUG -- : UserVisit Load (1.3ms) SELECT "user_visits".* FROM "user_visits" WHERE "user_visits"."user_id" = 1 AND "user_visits"."visited_at" = '2017-08-16' LIMIT 1 [["user_id", 1], ["visited_at", Wed, 16 Aug 2017]]
D, [2017-08-16T13:50:14.553588 #14047] DEBUG -- : SQL (3.5ms) UPDATE "users" SET "last_seen_at" = '2017-08-16 17:50:14.509563' WHERE "users"."id" = 1 [["id", 1]]
D, [2017-08-16T13:50:14.560300 #14047] DEBUG -- : (3.9ms) SELECT categories.id FROM "categories" LEFT OUTER JOIN "uploads" ON "uploads"."id" = "categories"."uploaded_logo_id" LEFT OUTER JOIN "uploads" "uploaded_backgrounds_categories" ON "uploaded_backgrounds_categories"."id" = "categories"."uploaded_background_id" WHERE "categories"."read_restricted" = 't' [["read_restricted", true]]
D, [2017-08-16T13:50:14.569177 #14047] DEBUG -- : Category Load (4.5ms) SELECT categories.*, t.slug topic_slug FROM "categories" LEFT JOIN topics t on t.id = categories.topic_id WHERE (NOT categories.read_restricted OR categories.id IN (2,3,4)) ORDER BY "categories"."position" ASC
D, [2017-08-16T13:50:14.580481 #14047] DEBUG -- : (0.9ms) SELECT "category_users"."category_id", "category_users"."notification_level" FROM "category_users" WHERE "category_users"."user_id" = 1
D, [2017-08-16T13:50:14.585194 #14047] DEBUG -- : (1.4ms) SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "topics" WHERE ("topics"."deleted_at" IS NULL) LIMIT 16) subquery_for_count
D, [2017-08-16T13:50:14.591761 #14047] DEBUG -- : (1.6ms) SELECT "users"."id" FROM "users" INNER JOIN "user_auth_tokens" ON "user_auth_tokens"."user_id" = "users"."id" WHERE "users"."admin" = 't' AND (users.id > 0) ORDER BY user_auth_tokens.created_at [["admin", true]]
D, [2017-08-16T13:50:14.597011 #14047] DEBUG -- : Topic Load (1.5ms) SELECT "topics".* FROM "topics" WHERE ("topics"."deleted_at" IS NULL) AND "topics"."slug" = 'welcome-to-discourse' ORDER BY "topics"."id" ASC LIMIT 1 [["slug", "welcome-to-discourse"]]
D, [2017-08-16T13:50:14.602911 #14047] DEBUG -- : User Load (1.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = -1 LIMIT 1 [["id", -1]]
D, [2017-08-16T13:50:14.608340 #14047] DEBUG -- : CACHE (0.0ms) SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "topics" WHERE ("topics"."deleted_at" IS NULL) LIMIT 16) subquery_for_count
D, [2017-08-16T13:50:14.613361 #14047] DEBUG -- : (1.8ms) SELECT "users"."id" FROM "users" INNER JOIN "user_auth_tokens" ON "user_auth_tokens"."user_id" = "users"."id" WHERE "users"."admin" = 't' AND (users.id > 0) ORDER BY user_auth_tokens.created_at [["admin", true]]
D, [2017-08-16T13:50:14.616927 #14047] DEBUG -- : CACHE (0.0ms) SELECT "topics".* FROM "topics" WHERE ("topics"."deleted_at" IS NULL) AND "topics"."slug" = 'welcome-to-discourse' ORDER BY "topics"."id" ASC LIMIT 1 [["slug", "welcome-to-discourse"]]
D, [2017-08-16T13:50:14.620538 #14047] DEBUG -- : CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = -1 LIMIT 1 [["id", -1]]
I, [2017-08-16T13:50:14.624538 #14047] INFO -- : Completed 500 Internal Server Error in 101ms (ActiveRecord: 26.5ms)
I, [2017-08-16T13:50:14.744330 #14047] INFO -- : Rendered /home.rvm/gems/ruby-2.3.1/gems/actionpack-4.2.9/lib/action_dispatch/middleware/templates/rescues/_source.erb (9.6ms)
I, [2017-08-16T13:50:14.755912 #14047] INFO -- : Rendered /home.rvm/gems/ruby-2.3.1/gems/actionpack-4.2.9/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (6.0ms)
I, [2017-08-16T13:50:14.765246 #14047] INFO -- : Rendered /home.rvm/gems/ruby-2.3.1/gems/actionpack-4.2.9/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (2.5ms)
I, [2017-08-16T13:50:14.769481 #14047] INFO -- : Rendered /home.rvm/gems/ruby-2.3.1/gems/actionpack-4.2.9/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (38.0ms)

```

And debug info:

 ![2017-08-16_20-53-57](https://global.discourse-cdn.com/meta/original/3X/b/d/bd031cd6519e810c728922e29bdbc2b44c36b342.jpg)

---

<div class="post-metadata">

**Author:** ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)\
**Post date:** [August 16, 2017, 11:14pm UTC](https://meta.discourse.org/t/cant-sign-in-as-admin-user-undefined-method-username-for-nil-nilclass/68169/2 "2017-08-16T23:14:07Z")

</div>

Can you try running `rake db:migrate`? The system user is missing on your installation for some reason.

---

<div class="post-metadata">

**Author:** ![almone](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/almone/32/120777_2.png) [@almone](https://meta.discourse.org/u/almone)\
**Post date:** [August 17, 2017, 7:19am UTC](https://meta.discourse.org/t/cant-sign-in-as-admin-user-undefined-method-username-for-nil-nilclass/68169/3 "2017-08-17T07:19:27Z")

</div>

This is what I get after running `rake db:migrate`:

```
vagrant@discourse:/vagrant$ rake db:migrateake db:migrate
== Seed from /vagrant/db/fixtures/001_categories.rb
Removing superflous categories columns!
rake aborted!
LoadError: Unable to autoload constant Version, expected /vagrant/lib/version.rb to define it
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/seed-fu-2.3.6/lib/seed-fu/runner.rb:46:in `eval'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/bootsnap-1.0.0/lib/bootsnap/load_path_cache/core_ext/active_support.rb:53:in `block in load_missing_constant'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/bootsnap-1.0.0/lib/bootsnap/load_path_cache/core_ext/active_support.rb:6:in `with_bootsnap_fallback'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/bootsnap-1.0.0/lib/bootsnap/load_path_cache/core_ext/active_support.rb:53:in `load_missing_constant'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.9/lib/active_support/dependencies.rb:184:in `const_missing'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.9/lib/active_support/inflector/methods.rb:261:in `const_get'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.9/lib/active_support/inflector/methods.rb:261:in `block in constantize'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.9/lib/active_support/inflector/methods.rb:259:in `each'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.9/lib/active_support/inflector/methods.rb:259:in `inject'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.9/lib/active_support/inflector/methods.rb:259:in `constantize'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/activesupport-4.2.9/lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
/vagrant/lib/discourse.rb:451:in `block in reset_active_record_cache'
/vagrant/lib/discourse.rb:450:in `each'
/vagrant/lib/discourse.rb:450:in `reset_active_record_cache'
/vagrant/lib/column_dropper.rb:42:in `drop'
(eval):29:in `block (2 levels) in run_file'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/seed-fu-2.3.6/lib/seed-fu/runner.rb:46:in `eval'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/seed-fu-2.3.6/lib/seed-fu/runner.rb:46:in `block (2 levels) in run_file'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/seed-fu-2.3.6/lib/seed-fu/runner.rb:58:in `block in open'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/seed-fu-2.3.6/lib/seed-fu/runner.rb:57:in `open'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/seed-fu-2.3.6/lib/seed-fu/runner.rb:57:in `open'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/seed-fu-2.3.6/lib/seed-fu/runner.rb:36:in `block in run_file'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.9/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.9/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.9/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/activerecord-4.2.9/lib/active_record/transactions.rb:220:in `transaction'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/seed-fu-2.3.6/lib/seed-fu/runner.rb:35:in `run_file'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/seed-fu-2.3.6/lib/seed-fu/runner.rb:26:in `block in run'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/seed-fu-2.3.6/lib/seed-fu/runner.rb:25:in `each'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/seed-fu-2.3.6/lib/seed-fu/runner.rb:25:in `run'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/seed-fu-2.3.6/lib/seed-fu.rb:29:in `seed'
/vagrant/lib/tasks/db.rake:20:in `block in <main>'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/home/vagrant/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
/home/vagrant/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

```

I also created admin user with `bundle exec rake admin:create`.

---

<div class="post-metadata">

**Author:** ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)\
**Post date:** [August 17, 2017, 7:21am UTC](https://meta.discourse.org/t/cant-sign-in-as-admin-user-undefined-method-username-for-nil-nilclass/68169/4 "2017-08-17T07:21:31Z")

</div>

Hmm it looks like running it in Vagrant is causing some sort of error. I personally don’t use Vagrant myself so I’ll let someone who does chip in.

---

<div class="post-metadata">

**Author:** ![almone](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/almone/32/120777_2.png) [@almone](https://meta.discourse.org/u/almone)\
**Post date:** [August 17, 2017, 7:29am UTC](https://meta.discourse.org/t/cant-sign-in-as-admin-user-undefined-method-username-for-nil-nilclass/68169/5 "2017-08-17T07:29:07Z")

</div>

By the way I tried to make clean [Docker based install](https://github.com/discourse/discourse/blob/master/docs/INSTALL.md) on DO – everything is working like a charm there.

---

<div class="post-metadata">

**Author:** ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)\
**Post date:** [August 17, 2017, 7:30am UTC](https://meta.discourse.org/t/cant-sign-in-as-admin-user-undefined-method-username-for-nil-nilclass/68169/6 "2017-08-17T07:30:50Z")

</div>

I believe the vagrant guide is meant for development purposes so I wouldn’t recommend running it in production.

---

<div class="post-metadata">

**Author:** ![almone](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/almone/32/120777_2.png) [@almone](https://meta.discourse.org/u/almone)\
**Post date:** [August 17, 2017, 7:39am UTC](https://meta.discourse.org/t/cant-sign-in-as-admin-user-undefined-method-username-for-nil-nilclass/68169/7 "2017-08-17T07:39:29Z")

</div>

I’m not going to use it on production. I’m trying to install in on my local dev server. The reason is what I want to make some changes to default template. For example I want best authors (most liked) to be shown on front page. Right now I have no idea how to do this. I think it would be easier to understand how template works on dev environment. But that’s another story…

---

<div class="post-metadata">

**Author:** ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)\
**Post date:** [August 17, 2017, 7:47am UTC](https://meta.discourse.org/t/cant-sign-in-as-admin-user-undefined-method-username-for-nil-nilclass/68169/8 "2017-08-17T07:47:16Z")

</div>

Ic. I got confused when mention the Docker based install which I took as you’re trying to get your production Discourse up and running. I’m personally don’t use Vagrant in development so you’ll have to wait for someone else that does.

---

<div class="post-metadata">

**Author:** ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)\
**Post date:** [August 17, 2017, 10:29am UTC](https://meta.discourse.org/t/cant-sign-in-as-admin-user-undefined-method-username-for-nil-nilclass/68169/9 "2017-08-17T10:29:18Z")

</div>

It turns out it wasn’t a problem with Vagrant. I was running into the same error in development as well. Fixed in

[https://github.com/discourse/discourse/commit/0e656ff213d11b0d416927763c284fa98f91aa5b](https://github.com/discourse/discourse/commit/0e656ff213d11b0d416927763c284fa98f91aa5b)

though I’m not sure why this wasn’t causing problems previously.

---

<div class="post-metadata">

**Author:** ![almone](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/almone/32/120777_2.png) [@almone](https://meta.discourse.org/u/almone)\
**Post date:** [August 17, 2017, 6:45pm UTC](https://meta.discourse.org/t/cant-sign-in-as-admin-user-undefined-method-username-for-nil-nilclass/68169/10 "2017-08-17T18:45:08Z")

</div>

Oh, thank you for your support! That works for me as well 👍

---

<div class="post-metadata">

**Author:** ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)\
**Post date:** [June 8, 2024, 12:44pm UTC](https://meta.discourse.org/t/cant-sign-in-as-admin-user-undefined-method-username-for-nil-nilclass/68169/11 "2024-06-08T12:44:23Z")

</div>

Closed on June 8, 2024, 12:44pm UTC

This topic was automatically closed after 2487 days. New replies are no longer allowed.
