I'm very new to Ruby on Rails. I created a model by running the rails g scaffold command, and then tried to run rails db:migrate in the wsl terminal which gave me this huge error:
rails db:migrate
/home/nidhi/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/railties-6.1.4.1/lib/rails/app_loader.rb:53: warning: Insecure world writable dir /mnt/c in PATH, mode 040777
Rails Error: Unable to access log file. Please ensure that /mnt/c/Windows/system32/railsfriends/friends/log/development.log exists and is writable (ie, make it writable for user and group: chmod 0664 /mnt/c/Windows/system32/railsfriends/friends/log/development.log). The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
(0.6ms) SELECT sqlite_version(*)
(0.3ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL PRIMARY KEY)
rails aborted!
ActiveRecord::StatementInvalid: SQLite3::ReadOnlyException: attempt to write a readonly database
/mnt/c/Windows/system32/railsfriends/friends/bin/rails:5:in `<top (required)>'
/mnt/c/Windows/system32/railsfriends/friends/bin/spring:10:in `block in <top (required)>'
/mnt/c/Windows/system32/railsfriends/friends/bin/spring:7:in `tap'
/mnt/c/Windows/system32/railsfriends/friends/bin/spring:7:in `<top (required)>'
Caused by:
SQLite3::ReadOnlyException: attempt to write a readonly database
/mnt/c/Windows/system32/railsfriends/friends/bin/rails:5:in `<top (required)>'
/mnt/c/Windows/system32/railsfriends/friends/bin/spring:10:in `block in <top (required)>'
/mnt/c/Windows/system32/railsfriends/friends/bin/spring:7:in `tap'
/mnt/c/Windows/system32/railsfriends/friends/bin/spring:7:in `<top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
I tried unchecking the "Read only" property of the development.log file it mentions, but that did not help. How can I solve this error?
Restarting my computer worked for me! I just had to go to my original folder and uncheck the "Read only" property, then restart the computer. The rails db:migrate command works now.
Related
I have a Rails application for which I wanna install the gem active storage so that I can save photos on my application and interact with them. Despite that, I input in the console
rails active_storage: install
and I get the following error:
rails aborted!
LoadError: cannot load such file -- active_storage
C:/Users/andri/Desktop/hoagieShop/hoagieShop/config/application.rb:4:in `require'
C:/Users/andri/Desktop/hoagieShop/hoagieShop/config/application.rb:4:in `<top (required)>'
C:/Users/andri/Desktop/hoagieShop/hoagieShop/Rakefile:4:in `require_relative'
C:/Users/andri/Desktop/hoagieShop/hoagieShop/Rakefile:4:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
(See full trace by running task with --trace)
Does anyone understand why? I tried the solution provided here: rails active_storage:install IS NOT WORKING but it did not work.
in terminal/app folder
reset db
rake db:reset
migrate db
rake db:migrate
update the gem file
bundle install
I have an pre-existing database named exam_prep in postgresql, which i am using in flask.
I have created a new Rails application and i want to use that database with it.
So far I have run rake db:structure:dump, which created a structure.sql under the db folder.
After that I ran db:structure:load, but got the following error:
psql:/Users/namangupta/Desktop/app/db/structure.sql:49: ERROR: type "batch_types_enum" already exists
rake aborted!
failed to execute:
psql -v ON_ERROR_STOP=1 -q -f /Users/namangupta/Desktop/app/db/structure.sql exam_prep
Please check the output above for any errors and make sure that `psql` is installed in your PATH and has proper permissions.
/Users/namangupta/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/tasks/postgresql_database_tasks.rb:108:in `run_cmd'
/Users/namangupta/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/tasks/postgresql_database_tasks.rb:80:in `structure_load'
/Users/namangupta/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:223:in `structure_load'
/Users/namangupta/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:236:in `load_schema'
/Users/namangupta/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:255:in `block in load_schema_current'
/Users/namangupta/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:304:in `block in each_current_configuration'
/Users/namangupta/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:303:in `each'
/Users/namangupta/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:303:in `each_current_configuration'
/Users/namangupta/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:254:in `load_schema_current'
/Users/namangupta/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/railties/databases.rake:290:in `block (3 levels) in <top (required)>'
/Users/namangupta/.rvm/gems/ruby-2.3.4/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
/Users/namangupta/.rvm/gems/ruby-2.3.4/bin/ruby_executable_hooks:15:in `eval'
/Users/namangupta/.rvm/gems/ruby-2.3.4/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:structure:load
(See full trace by running task with --trace)
I want Rails to use the database and make a models within this. Any ideas?
The db:structure:load rake task creates a tables and columns from the structure.sql or schema.rb. You shouldn't need to run it, as your existing database already has all the tables you need.
Your next step would be to go about creating your model files and pointing them at the appropriate tables.
So I am trying to do bundle install . But it is throwing the below errors. What is the problem here?
bundle exec rake db:create:all
DEPRECATION WARNING: String based terminators are deprecated, please use a lambda. (called from included at /home/.gem/ruby/2.1.3/bundler/gems/authlogic-09163c7d2a9b/lib/authlogic/session/callbacks.rb:66)
DEPRECATION WARNING: String based terminators are deprecated, please use a lambda. (called from included at /home/.gem/ruby/2.1.3/bundler/gems/authlogic-09163c7d2a9b/lib/authlogic/session/callbacks.rb:67)
rake aborted!
Cannot load `Rails.application.database_configuration`:
Could not load database configuration. No such file -
/home/.gem/ruby/2.1.3/gems/railties-4.1.5/lib/rails/application/configuration.rb:105:in `database_configuration'
/home/.gem/ruby/2.1.3/gems/activerecord-4.1.5/lib/active_record/railtie.rb:43:in `block (3 levels) in <class:Railtie>'
Could not load database configuration. No such file -
/home/.gem/ruby/2.1.3/gems/railties-4.1.5/lib/rails/application/configuration.rb:105:in `database_configuration'
/home/.gem/ruby/2.1.3/gems/activerecord-4.1.5/lib/active_record/railtie.rb:43:in `block (3 levels) in <class:Railtie>'
Tasks: TOP => db:create:all => db:load_config
(See full trace by running task with --trace)
Earlier I had tried the below:
rake db:create:all
rake aborted!
Gem::LoadError: You have already activated rake 10.4.2, but your Gemfile requires rake 10.3.2. Prepending `bundle exec` to your command may solve this.
/home/.gem/ruby/2.1.3/gems/bundler-1.7.12/lib/bundler/runtime.rb:34:in `block in setup'
/home/.gem/ruby/2.1.3/gems/bundler-1.7.12/lib/bundler/runtime.rb:19:in `setup'
/home/.gem/ruby/2.1.3/gems/bundler-1.7.12/lib/bundler.rb:122:in `setup'
/home/.gem/ruby/2.1.3/gems/bundler-1.7.12/lib/bundler/setup.rb:7:in `<top (required)>'
/home/project/config/boot.rb:4:in `<top (required)>'
/home/project/config/application.rb:1:in `<top (required)>'
/home/project/Rakefile:4:in `<top (required)>'
LoadError: cannot load such file -- bundler/setup
/home/project/config/boot.rb:4:in `<top (required)>'
/home/project/config/application.rb:1:in `<top (required)>'
/home/project/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
$ bundle exec rake db:create:all
DEPRECATION WARNING: String based terminators are deprecated, please use a lambda. (called from included at /home/.gem/ruby/2.1.3/bundler/gems/authlogic-09163c7d2a9b/lib/authlogic/session/callbacks.rb:66)
DEPRECATION WARNING: String based terminators are deprecated, please use a lambda. (called from included at /home/.gem/ruby/2.1.3/bundler/gems/authlogic-09163c7d2a9b/lib/authlogic/session/callbacks.rb:67)
rake aborted!
Cannot load `Rails.application.database_configuration`:
Could not load database configuration. No such file -
/home/.gem/ruby/2.1.3/gems/railties-4.1.5/lib/rails/application/configuration.rb:105:in `database_configuration'
/home/.gem/ruby/2.1.3/gems/activerecord-4.1.5/lib/active_record/railtie.rb:43:in `block (3 levels) in <class:Railtie>'
Could not load database configuration. No such file -
/home/.gem/ruby/2.1.3/gems/railties-4.1.5/lib/rails/application/configuration.rb:105:in `database_configuration'
/home/.gem/ruby/2.1.3/gems/activerecord-4.1.5/lib/active_record/railtie.rb:43:in `block (3 levels) in <class:Railtie>'
Tasks: TOP => db:create:all => db:load_config
(See full trace by running task with --trace)
You are trying to run "rake db:create:all" which would create your database but as error states - it seems you don't have your config/database.yml file. It's a configuration file that tells rails how to connect to your database. You can read more about it here.
If you really want to run bundle install, just use "bundle install" command instead. This will install all gems listed in your Gemfile.
If you will get problems with rake version conflicts, check out this stack overflow question.
It seems you have no config/database.yml file in your project's directory.
Why I think so? Follow me ...
Could not load database configuration. No such file -
/home/.gem/ruby/2.1.3/gems/railties-4.1.5/lib/rails/application/configuration.rb:105:in `database_configuration'
Ok, let's take a look at this code where we have error:
yaml = Pathname.new(paths["config/database"].existent.first || "")
config = if yaml.exist?
require "yaml"
require "erb"
YAML.load(ERB.new(yaml.read).result) || {}
elsif ENV['DATABASE_URL']
# Value from ENV['DATABASE_URL'] is set to default database connection
# by Active Record.
{}
else
raise "Could not load database configuration. No such file - #{yaml}"
end
As you can see - if no such file or ENV variable then rails throws error.
I have been following a video tutorial and the database is created, but when trying to follow the step by going to directory and entering rake: dbmigrate
I get an error.
Ians-MacBook-Pro:music_library iansherwood$ rake db migrate
rake aborted!
dlopen(/Users/iansherwood/Sites/music_library/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.13/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/iansherwood/Sites/music_library/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.13/lib/mysql2/mysql2.bundle
Reason: image not found - /Users/iansherwood/Sites/music_library/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.13/lib/mysql2/mysql2.bundle
/Users/iansherwood/Sites/music_library/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.13/lib/mysql2.rb:8:in `require'
/Users/iansherwood/Sites/music_library/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.13/lib/mysql2.rb:8:in `<top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p392#global/gems/bundler-1.2.4/lib/bundler/runtime.rb:68:in `require'
/usr/local/rvm/gems/ruby-1.9.3-p392#global/gems/bundler-1.2.4/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
/usr/local/rvm/gems/ruby-1.9.3-p392#global/gems/bundler-1.2.4/lib/bundler/runtime.rb:66:in `each'
/usr/local/rvm/gems/ruby-1.9.3-p392#global/gems/bundler-1.2.4/lib/bundler/runtime.rb:66:in `block in require'
/usr/local/rvm/gems/ruby-1.9.3-p392#global/gems/bundler-1.2.4/lib/bundler/runtime.rb:55:in `each'
/usr/local/rvm/gems/ruby-1.9.3-p392#global/gems/bundler-1.2.4/lib/bundler/runtime.rb:55:in `require'
/usr/local/rvm/gems/ruby-1.9.3-p392#global/gems/bundler-1.2.4/lib/bundler.rb:128:in `require'
/Users/iansherwood/Sites/music_library/config/application.rb:7:in `<top (required)>'
/Users/iansherwood/Sites/music_library/Rakefile:5:in `<top (required)>'
(See full trace by running task with --trace)
Have you tried bundle exec rake db:migrate?
Another possibility is that you don't have my MySQL running.
The easiest way to check for that would be:
ps aux | grep mysql
If it isn't running and you installed MySQL through
homebrew (common video guide way to install it) then you can run mysql.server start.
The syntax should be: rake db:migrate, and not rake: dbmigrate or rake db migrate.
It looks like your colon use might be inconsistent. Remember to use:
rake db:migrate
http://guides.rubyonrails.org/command_line.html
Did you include "gem 'mysql2'" in your Gemfile?
I tried running rake db:reset in my rails application after bundle install. The following message is displayed
rake aborted!
cannot load such file -- indirizzo
/home/xyz/Desktop/Signup4/app/models/concerns/address_validation.rb:2:in `<module:AddressValidation>'
/home/xyz/Desktop/Signup4/app/models/concerns/address_validation.rb:1:in `<top (required)>'
/home/xyz/Desktop/Signup4/app/models/location.rb:2:in `<class:Location>'
/home/xyz/Desktop/Signup4/app/models/location.rb:1:in `<top (required)>'
/home/xyz/Desktop/Signup4/db/seeds.rb:11:in `<top (required)>'
Tasks: TOP => db:setup => db:seed
(See full trace by running task with --trace)
bundle show Indirizzo displays
/usr/local/lib/ruby/gems/2.0.0/gems/Indirizzo-0.1.7
It seems to me the problem is in correct require.
According to readme https://github.com/daveworth/Indirizzo#usage it should be
require 'Indirizzo'
but the fact that it does not work (the same error).
It think it should be the same as in the internal lib https://github.com/daveworth/Indirizzo/blob/master/lib/indirizzo.rb
require 'indirizzo/address'
after this I manage to complete this example Indirizzo::Address.new("some address")