I am trying out an example from a book head first rails, i get to chapter 2 and i have issues following the instructions maybe because they used an older version of rails.
I am told to replace the development.sqlite3 file with the one provided on the site, and when i do so and try to run the run app again i get errors about pending migrations.
Note:
1. I already ran my migration using rake db:migrate
2. I downloaded the sqlite3 file and replaced the original file.
3. i started the server with rails s command.
4. I reload the page and then i get the error.
ActiveRecord::PendingMigrationError
Migrations are pending. To resolve this issue, run: bin/rails db:migrate RAILS_ENV=development
I have a feeling it has something to do with the schema.rb file? i dunno.
I'll really appreciate if someone can help me out here.
I have done my research, i've tried rake db:reset but to no avail. :(
see here:
[1]: http://headfirstlabs.com/books/hfrails you can scroll down to the code download section under chapter 2.
Related
I am newbie with Rails and having this problem.
I created a rails folder named freelancer. Everthing seems ok.
Then, I went to this folder and ran this cmd :
rails db:setup
It said to me this error : /freelancer/db/schema.rb doesn't exist yet. Run rails db*migrate to create it, then try again. If you do not intend to use a database, you should instead alter /home/anh/Desktop/freelancer/config/application.rb to limit the frameworks that will be loaded
Then I ran this command as they said
rails db:migrate
Then I ran the command rails db:setup, they said to me that
Database 'bai9freelancer_development' already exists
Database 'bai9freelancer_test' already exists
I am very confusing because those problem. First, when I create my rails folder freelancer, no problem. Why schema.rb doesn't exist ? Second, They said to me that I must run rails db:migrate then try rails db:setup again, then they said to me that already exists. That why ? Could you please explain those problem for me ? Thank you very much.
When you ran
rails db:migrate
you already created db/schema.rb
Running rails db:setup is the equivalent of
rails db:create
rails db:migrate
rails db:seed
So after you ran rails db:migrate you don't need to recall rails db:setup anymore. You can find out more in the documentation here
I'm cloning a RoR app from Github. After the clone I install my gems. Now at this point my question/problem arises. Some research I've done suggests I do a
rake db:create
followed by a
rake db:migrate
I've tried both of those steps but am still having trouble.
When I run
rails console
and do something like Plan.first it returns nil. And when I try to visit my application I get an ActiveRecord::RecordNotFound in PagesController#home error alluding to the fact that it can't find the plan id of 1.
Any help is much appreciated.
Thanks in advance!
You have an empty database with no data in it, if seeds are provided - rake db:seed will help, otherwise you'll have to create initial data youself (in rails console, or may be directly in db)
First time here, I hope do it right.
I'm following the railstutorial 3.2 and I'm in section 5.4, in the paragraph above to listing 5.32.
(In fact, you can just type rake by itself; the default behavior of rake is to
run the test suite.)
I used rake by itselft but I have a error since then. When I run:
"$ bundle exec rake spec" I get this error.
http://pastebin.com/F0wrEkT1
My database.yml is:
http://pastebin.com/tWAgeFTV
My problem is that I don't know why it is asking for production database when I didn't use it yet. And whe I look for the issue I don't find topics about (almost I didn't find it).
Do you have some clues to star looking or to know what is happening?
Thanks a lot.
I'm not sure why it is looking for the production DB but you may want to skip ahead. Just read a little further:
(In fact, you can just type rake by itself; the default behavior of rake is to run the test suite.) The only caveat is that using rake to run the tests for the current sample application will raise an error since it requires the test database to be prepared properly, a step we’ll defer to Section 6.2.1.
It recommends running:
bundle exec rake db:test:prepare
After rake db:migrate:rollback STEP=1, rake db:migrate:reset, rake db:migrate:setup, rake db:migrate:up VERSION=XXXXXXXXX I get the following entry:
Status Migration ID Migration Name
------------------------------------------------------
up 0 *********NO FILE**********
up 20120209023430 Create tasks
How can I get rid of the orphaned entry? I have encountered this problem a few times after raking the db similar to above. Could somebody please explain what exactly causes this.
Thx in advance.
Shahram
You could use rake db:migrate:reset db:seed. It's a little less verbose and will completely wipe your database, re-run all migrations, and then seed your database from the db/seeds.rb file.
I've just released this gem that can solve this issue for good.
The idea of that gem is simple. It keeps all migrated migrations inside tmp folder so that Git ignores them. It's just only your local story. These files are needed to roll back the "unknown" migrations being in another branch. Now, whenever you have an inconsistent DB schema due to running migrations in some other branch just run rails db:migrate inside the current branch and it will fix the issue automatically. The gem does all this magic automatically for you.
I made what I now see as a mistake (better now than later, not as good as never) of running rake db:reset on my local dev env to try to solve a problem I was having with assets production compilation(RAILS_ENV=production bundle exec rake assets:precompile) referring to a PG ERROR summarized bellow.
PGError: ERROR: relation "schools" does not exist
LINE 4: WHERE a.attrelid = '"schools"'::regclass
The tables get created properly and seeding works with exception of active_admin. I use Active_Admin that did not seed properly. My emails mysteriously stopped being sent and the assets compilation for production still fails with the same error. I am not sure what I can post here to help you understand the issue but if someone could help me tackle one at a time that would be much appreciated. Here are my issues in list form.
active_admin not seeding (I tried running: rails generate active_admin:install but that started to break things further so I reverted this.
PG ERROR on assets precompile for production persists.
Email stopped being processed (not using DJ)
Env.
Rails 3.1
------UPDATE 00------
2 is Solved. db:reset dropped all my tables but only migrated and seeded my development database so I also had to:
run migrate and seed for production ( rake db:migrate RAILS_ENV="production", rake db:seed RAILS_ENV="production")
before compiling production assets(rake db:migrate RAILS_ENV="production")
I ended up splitting this question into 2 parts. The second part got better contribution and is where I found the solution for this as well.
Detailed solution here