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

I’m having an issue with logging in as admin user.
I made a clean Vagrant install according to this guide.
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:

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

2 Likes

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.

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.

By the way I tried to make clean Docker based install on DO – everything is working like a charm there.

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

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…

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.

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

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

7 Likes

Oh, thank you for your support! That works for me as well :+1: