$ bundle exec rake db:reset command raising couldn't drop db/development.sqlite3
When you do db:reset
, it's running db:drop
and db:setup
in sequence. Your error message indicates that db/development.sqlite
couldn't be deleted.
If you're on Windows, maybe you need to stop your Rails server and console. Otherwise, figure out what's preventing the file from being deleted. It could be permission problem. A reboot may solve the problem too.
rails 5 db:reset not working
Usually when rake db:reset
don't run or work for me, I just delete the development.sqlite3 and schema.rb files and re run the rake db:migrate
command to regenerate both files. But take note to Never try this in a production environment please.
Purge or recreate a Ruby on Rails database
I know two ways to do this:
This will reset your database and reload your current schema with all:
rake db:reset db:migrate
This will destroy your db and then create it and then migrate your current schema:
rake db:drop db:create db:migrate
All data will be lost in both scenarios.
rake db:migrate does not create table
You actually didn't do anything wrong. Look in db/schema.rb and if you see this then you're database is setup properly:
ActiveRecord::Schema.define(version: 20161019035406) do
create_table "ads", force: :cascade do |t|
t.string "name"
t.text "description"
t.decimal "price"
t.integer "seller_id"
t.string "email"
t.string "img_url"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end
If you're getting an error that the table already exists, you can do the following:
first add a down
method to your migration file that you used to generate the ads table. The down method would look like this:
def down
drop_table :ads
end
Then run rake db:migrate:down VERSION=version_number
where the version_number is the timestamp in the name of the migration file. This will remove the table from the database. Then change the name of the change
method to up
. Save the file and run rake db:migrate:up
to create the table again.
Can't execute bundle exec rake db:migrate due to tzinfo error
Thanks for the suggestions guys, it helped me a lot. The proper to solution to my problem was:
- remove gemfile.lock
- decrease tzinfo version to 1.2.1, and leave tzinfo-data as provided
by user3097405. - Then another error occured so I had to increase sqlite3 version to
1.3.11. Also it turned out I can decomment webconsle.
So, in the end the Gemfile looks like this
source 'https://rubygems.org'
gem 'rails', '4.2.2'
gem 'sass-rails', '5.0.2'
gem 'uglifier', '2.5.3'
gem 'coffee-rails', '4.1.0'
gem 'jquery-rails', '4.0.3'
gem 'turbolinks', '2.3.0'
gem 'jbuilder', '2.2.3'
gem 'sdoc', '0.4.0', group: :doc
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]
gem 'tzinfo', '1.2.1'
group :development, :test do
gem 'sqlite3', '1.3.11'
gem 'byebug', '3.4.0'
gem 'web-console', '2.0.0.beta3'
gem 'spring', '1.1.3'
end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
end
And after one more bundle install
the rake command executed properly.
rake db:migrate does nothing
If you are connecting to the right database everything seems fine to me.. I had a similar problem a few weeks ago and the accepted answer of this question fixed my issue.
Here are the steps to run:
rake db:drop:all
rake db:create:all
rake db:migrate
I hope it will fix your problem.
WARNING: this will erase your database.
How can I change from SQLite database to PostgreSQL database in a working Rails project for localhost?
You need to install postgresql package into your system you can refer to this link for instruction regarding installing postgres all you need to do is execute the following commands
sudo apt-get install postgresql postgresql-contrib
this installs postgres into your system
then you need to create a user with the details that you have mentioned in the database.yml file of your rails application
You can use pgadmin for db browser you can refer to this question for other tools
to install pgadmin3 run the following command
sudo apt-get install pgadmin3
then configure it with the details like host port etc that you are using(refer to database.yml)
Ruby on Rails error ActiveRecord::PendingMigrationError
Your first try was close, you need to do
rake db:drop
rake db:create
rake db:schema:load
Check this article it may be helpful.
http://icebergist.com/posts/rake-db-migrate-vs-rake-db-schema-load/
Related Topics
Convert Datetime String to Utc in Rails
How to Log the Entire Trace Back of a Ruby Exception Using the Default Rails Logger
Rails Activeadmin - Custom Association Select Box
Checking If a Method Is Defined on the Class
All Possible Permutations of a Given String
Rails: Ensure Only One Boolean Field Is Set to True at a Time
Resque Multiple Workers in Development Mode
Best Way to Combine Fragment and Object Caching for Memcached and Rails
How to Delete Specific Characters from a String in Ruby
How to Write Specs for Code That Depends on Environment Variables
Confusing Behaviour of Const_Get in Ruby
Ruby: Explicit Scoping on a Class Definition
Ruby - Bundle Install/Update Too Slow
Find Records with Datetime That Match Today's Date - Ruby on Rails