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
Related
I'm working on api projects in rails 4. I created all models by command rails g model myModel, some action in db/migrate has been created a file for migration db, which I do not use for this migrate.
If I run some controller, example localhost:3000/report/data
I found some error :
"Migrations are pending. To resolve this issue, run:
bin/rake db:migrate RAILS_ENV=development"
It means that, I've to run rails & migrate for every model that I created in my project.
how can I pass it for all models in rails 4? Thanks in advance.
I think you can skip migration creation using the command
rails g model User --skip-migration
Just run
rake db:reset
and then
rake db:migrate
You should run
bin/rake db:migrate RAILS_ENV="development"
I'm new to Ruby on Rails and following Michael Hartls Ruby on Rails Tutorial. When I run bundle rake exec test, I am getting this error:
ERROR["test_should_get_new", SessionsControllerTest, 2.331314]
test_should_get_new#SessionsControllerTest (2.33s)
ActiveRecord::StatementInvalid:
ActiveRecord::StatementInvalid: Could not find table 'users'
and once similar for all of my tests. I see that my test database: test.sqlite3 is empty. My development database development.sqlite3 does have the users table in it.
I tried running the following to attempt cloning the users database to the test database, but nothing is working:
rake db:migrate:reset
rake db:migrate db:test:prepare
rake db:test:clone
rake db:test:prepare
rake db:test:load
but it's still empty. Any suggestions please?
I think you might be able to get it with:
RAILS_ENV=test rake db:migrate
Give it a try, I've had this problem before myself. I believe that
rake db:test:prepare
is deprecated. What version of ruby and rails are you using?
I figured out a fix, although I'm still not sure why there was a problem to begin with. What I did was I took the pure Sql CREATE TABLE used to create the development table and executed it in the users table. Now everything is working fine.
I have tried to run as a server before and it worked well, I don't change anything in the database but when I tried to run again a have this message Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=development
i tried as this site link
but it failed
any help please
i am a beginner in ruby on rails
Migration files live in the db/migrate directory, and their names look like this:
20150121164407_create_comments.rb
From your comment, it looks like inside your db/migrate directory, you have several migrations with the same “basic” name create_comments (and probably different timestamps).
You need to remove one of those duplicated files.
If you did and if you don't have any important data in the database, you should destroy your database and recreate it using existing migrations. These commands in this order:
$ rake db:drop
if you're using postgres
$ rake db:create
and finally remigrate
$ rake db:migrate
I'm newbie with ror and I just managed to ruin the databse... I tried to recreate with this 2 methodes bu none works:
first:
rake db:reset
rake db:migrate
second:
rake db:drop
rake db:create
rake db:migrate
But none work... I'm out of ideas what to do, please help...
My migrate folder is empty, if I migrate nothing happens, no table created notice.
Try using:
rake db:migrate:reset
examine your database.yml file, it might default to SQLITE which is basically a text file.
Make sure you are using the correct database with the correct name.
I have two instances of my app: one for development, one for production. My development database is called snip_development and my production database is called snip.
I've been doing migrations all along in my development environment and it's been going just fine. I recently created a production instance of my app but rake db:migrate doesn't seem to have any effect. After I run rake db:migrate and log into my database server, I can see that snip_development has all the tables I expect it to but snip doesn't have any tables at all.
I suspect the problem is that rake db:migrate is running on snip_development instead of snip and that's why I'm not seeing anything happen.
How do I get my migrations to work on my production database?
Sometimes I forget about Google. The answer is this:
rake db:migrate RAILS_ENV=production
For me the answer above not works. I have to add bundle exec to make it works.
bundle exec rails db:migrate RAILS_ENV=production