Elixir Unknown Registery Error on Pubsub upgrade

I recently upgraded the pubsub dependency in my project following the documentation, but I am getting this error whenever I run the server:

an exception was raised:
** (ArgumentError) unknown registry: Demo.PubSub
    (elixir 1.10.2) lib/registry.ex:1239: Registry.info!/1
    (elixir 1.10.2) lib/registry.ex:920: Registry.register/3
    (phoenix_pubsub 2.0.0) lib/phoenix/pubsub.ex:117: Phoenix.PubSub.subscribe/3
    (phoenix 1.5.8) lib/phoenix/channel/server.ex:420: Phoenix.Channel.Server.init_join/3
    (phoenix 1.5.8) lib/phoenix/channel/server.ex:378: Phoenix.Channel.Server.channel_join/4
    (phoenix 1.5.8) lib/phoenix/channel/server.ex:298: Phoenix.Channel.Server.handle_info/2
    (stdlib 3.7) gen_server.erl:637: :gen_server.try_dispatch/4
    (stdlib 3.7) gen_server.erl:711: :gen_server.handle_msg/6

Here is my application.ex

def start(_type, _args) do
# List all child processes to be supervised
children = [
  Demo.Repo,
  {Demo.ExpireCodesJob, []},
  {Demo.DistributeCodesJob, []},
  {Oban, oban_config()},
  DemoWeb.Endpoint,
  {Phoenix.PubSub, [name: Demo.PubSub, adapter: Phoenix.PubSub.PG2]},
  worker(PlugAttack.Storage.Ets, [Demo.PlugAttack.Storage, [clean_period: 60_000]])
]

Here is my config.ex

# Configures the endpoint
config :demo, DemoWeb.Endpoint,
  url: [host: System.get_env("HOST")],
  secret_key_base: System.get_env("SECRET_KEY_BASE"),
  render_errors: [view: DemoWeb.ErrorView, accepts: ~w(json)],
  pubsub_server: Demo.PubSub,
  check_origin: [...]

I’ve searched a lot about it, but since I am still a newbie, could not figure out where does it goes wrong. Please help me out.

Try starting the pubsub before your endpoint in your application.ex and see if it fixes it. (I.e. move it earlier in the children list.)

I’ve already tried moving it to right above and below the Pubsub endpoint and also right below the Demo.Repo, but no use