The user, Maight723, encountered an error while executing an import script in a Discourse installation, receiving a NoDatabaseError indicating the database discourse could not be found. Despite the site running normally and the database being accessible via psql and rails c, the import script failed. pfaffman suggested checking the database configuration and ensuring Discourse was functioning correctly. After confirming a standard install and that the issue persisted across environments, Maight723 realized the script was being run as root instead of the discourse user. Running the script as the discourse user resolved the issue Maight723.
I have successfully migrated a forum to Disourcse with a custom script before, but now when I execute it again, I get the following import error:
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/postgresql_adapter.rb:81:in `rescue in new_client': We could not find your database: discourse. Which can be found in the database configuration file located at config/database.yml. (ActiveRecord::NoDatabaseError)
To resolve this issue:
- Did you create the database for this app, or delete it? You may need to create your database.
- Has the database name changed? Check your database.yml config has the correct database name.
To create your database, run:
bin/rails db:create
./launcher enter app
cd /var/www/discourse
bundle exec ruby script/import_scripts/avatar.rb
I don’t really understand the error though: I can access the database through sudo -u postgres psql discourse, validating that the database “discourse” does exist. Also, the website is running fine. When I open rails c I can also access the data.
Can you give me some pointers what’s messed up there?
Discourse can’t find its database. So you need to fix that. Was this a standard install or a development install? Have a look at the appropriate guide and make discourse work as the first step.
I did reboot and it didn’t fix the issue. I now also encounter the same issue on my local machine (local docker)… which makes me think that somehow I run the command somehow incorrectly…
And thank you – I celebrate the swiftness of your responses and the support!