this is what I get when I run the project
Hi, I'm working on a project.
When I run my project, I got this problem:
Migrations are pending. To resolve this issue, run:
bin/rake db:migrate RAILS_ENV=development
raise ActiveRecord::PendingMigrationError if ActiveRecord::Migrator.needs_migration?
(connection)
I've already tried several solutions below:
1)
rake db:drop
rake db:create
rake db:migrate
2) bundle exec rake db:migrate
3) bin/rake db:migrate RAILS_ENV=development
but they didn't work, and I got the same error over and over again.
What can I do?
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/
$ rm db/schema.rb
$ bundle exec rake db:drop
$ bundle exec rake db:create
$ bundle exec rake db:migrate
Or just rake db:reset. That always works for me, when I get stuck.
Related
I have an application in rails 4.2.7.1, when I run the db:migrate in test in works perfectly
➜ bundle exec rake db:drop RAILS_ENV=test
➜ bundle exec rake db:ceate RAILS_ENV=test
➜ bundle exec rake db:migrate RAILS_ENV=test
But when I ran it in development, only the last migration or beginning from a drop database after executing firs migration I get this:
➜ bundle exec rake db:migrate -- --trace
== 20191112204156 MyNewModel: migrating ==============================
-- create_table(:global_clients)
-> 0.0121s
== 20191112204156 MyNewModel: migrated (0.0122s) =====================
rake aborted!
SystemStackError: stack level too deep
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
I'm using ruby 2.1.6, and mysql 0.318 and later 0.4.10, I did rvm implode to start it again and nothing happens. I do not know how to solve it, even I do not know how to debug it. So any tips will be good.
It's a problem with dthe difference from rais test and development environments
After this error in my web page when i have run > rake db:migrate. It shows error such as:
rake aborted!
you have already activated rake 10.1.1 but you gemfile requires rake 10.1.0 using bundle exec may solve this.
when i tried with bundle exec rake db:migrate it works.
And when i tried with the rake db:migrate. i shows error
My question is:
What is the difference between bundle exec rake db:migrate and rake db:migrate.
every time i have to do like this if yes then why?
What is the problem in my project.
Thanks.
bundle exec rake db:migrate will run rake db:migrate with the environment of your Gemfile.
You have an error because your Gemfile requires a version of rake but you have a newer one installed on your system.
By default, rake will run the latest available version, hence the mismatch.
You should always prefix your commands with bundle exec inside a project managed by bundler, I personally alias bx to bundle exec.
You can also use binstubs
Try to run bundle update.
It seems, that your Gemfile.lock is out of sync with your Gemfile.
Utterly confused at this mess:
rake db:drop
>
rake db:create
> my_database already exists
rake db:migrate
> unknown database my_database
Appreciate any insight.
That's because first time when u do rake db:create it creates two databases one is development and other is test. then when u do rake db:drop it drops the database, but it only drops the development database not the test database. so try removing the test database explicitly and everything should be fine.
Try :
rake db:drop
rake db:create RAILS_ENV=development
rake db:migrate RAILS_ENV=development
if getting same error then open mysql terminal and create database manually :
CREATE DATABASE database_name;
then run
rake db:migrate
I created reset_db.bat on Windows with the following content:
rake db:drop RAILS_ENV=development
rake db:create
rake db:migrate
rake db:seed
When I type reset_db only the first command (drop) is executed. Why ?
I assume that the rake is also a .bat file.
Then you only have to prepend it with a call
call rake db:drop RAILS_ENV=development
call rake db:create
call rake db:migrate
call rake db:seed
How can I create a production database in Rails 3 and load a schema to it?
I tried the following approaches...
I.
rake db:create Rails.env='production' && rake db:schema:load Rails.env='production'
II.
# config/environment.rb
# Set the rails environment
Rails.env='production'
rake db:create && rake db:schema:load
... but neither of them works.
Thanks.
Debian GNU/Linux 5.0.6;
Rails 3.0.0;
Sqlite3 3.7.2.
You can set the rails env off of the environment variable RAILS_ENV
RAILS_ENV=production bundle exec rake db:create db:schema:load
should work
Shouldn't this be
RAILS_ENV=production bundle exec rake db:create db:schema:load