I just cloned an application from my developer and I want to set it up on my computer. I get this error when I go to localhost:3000, and I don't really understand what it means.
Error:
ActiveRecord::StatementInvalid - Mysql2::Error: Table
'goacquire_development.sessions' doesn't exist: SHOW FULL FIELDS FROM `sessions`:
I think it could be my installation process, I'll appreciate if someone could explain this error to me.
A few ideas:
Make sure MySQL is running on your local machine.
Make sure you have run rake db:create and rake db:migrate.
Make sure you have a database.yml file configured with MySQL settings.
Hope this helps.
Install MySQL server on your machine
Config database.yml (Create new if your app don't have.)
Run commands:
# cd /path/to/your/app
# bundle install
# rake db:create
# rake db:migrate
# rails s
Related
I want to create a MySQL database in Ruby on Rails using:
rake db: create
But it gives me out an error:
rake aborted! Don't know how to build task 'db:'
I am running Ubuntu and cant find answers on the internet about my version of rake (10.4.2).
It's rake db:create without a blank between db: and create.
If you type rake -T you can find the available rake tasks with their proper names.
The database is created, tables are created, data are there.
But after I restarted the Rails application, I got this error. The app is using MySQL.
What's the issue here?
Thank you in advance
Solution
Simply run
rake db:migrate
There are migrations that need to be ran before your server can start. Learn what migrations are and how they are used in Rails with this RailsGuide.
Run that rake db:migrate command any time you make a migration, or any time you create a new project. If you get an error saying that migrations are pending, this is the answer. Then try to start the server again.
Only if that doesn't work, try what is below.
If that doesn't work
Run these commands in this order:
rake db:drop
rake db:create
rake db:migrate
rake db:seed - This one is only necessary if you have seeded data.
Remember, when in doubt: restart the server!
just run rake db:migrate then start server, see then what happens, looks like existing migrations are yet not part of schema. Or you schema_migrations table might be missing some version value.
Try to run bundle exec rake db:migrate RAILS_ENV=developmentfor me running just bundle exec rake db:migrate didn't resolve the issue
As one of the comments above, utilizing the following works for me:
rake db:drop
rake db:create
rake db:migrate
when rake db:migrate or restarting didn't help.
I'm new to ruby and mysql.
I was told to execute two commands below:
mysql -u root; then CREATE DATABASE sd
rake db:migrate.
The sd database was empty when created. After I ran the 2nd command, sd is full of items.
I'm wondering how rake knows that the destination is sd and what the source is.
I know that there are some scripts under db/migrate folder, so I guess rake knows who the destination is from such newly-created(I assume, 'cause I'm new to ruby) scripts. But how about the source?
Thanks!
The source of the data will normally be controlled by the db/migrate/*.rb files as you are aware of.
But they may have hooked another task onto db:migrate via the Rakefile or lib/tasks/*.rake files so "rake db:mirgrate" may also runs some extra tasks. A common task that adds seed information is the rake db:seed task, which normally runs db/seeds.rb .
When I use db/seeds.rb I typically put my seed data in db/fixtures/*.yml, but others may have different places.
on newer rails you can also use rake db:create to do the database creation (assuming the user in database.yml has sufficient privileges). rake -T db will tell you wnat tasks have been named with db in them, eg:
$ rake -T db
rake db:create # Create the database from DATABASE_URL or config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)
rake db:drop # Drops the database using DATABASE_URL or the current Rails.env (use db:drop:all to drop all databases)
rake db:fixtures:load # Load fixtures into the current environment's database.
rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false).
rake db:migrate:status # Display status of migrations
rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n).
rake db:schema:dump # Create a db/schema.rb file that can be portably used against any DB supported by AR
rake db:schema:load # Load a schema.rb file into the database
rake db:seed # Load the seed data from db/seeds.rb
rake db:seed_fu # Loads seed data for the current environment.
rake db:setup # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first)
rake db:structure:dump # Dump the database structure to db/structure.sql. Specify another file with DB_STRUCTURE=db/my_structure.sql
rake db:test:seed # seed the test database
rake db:version # Retrieves the current schema version number
It looks like you are trying to work with a Rails application. I would suggest looking at config/database.yml. That file holds configuration data for test, development, and production environments. By default, rails uses the development environment. You will likely find the answer in config/database.yml under development section.
Duck
All information about your database is on the file config/database.yml. This doc can help you: http://guides.rubyonrails.org/configuring.html#configuring-a-database
And you can change this:
mysql -u root; then CREATE DATABASE sd
for that:
rake db:create
With Rails, how do you migrate data from development sqlite3 database to production MySQL database?
How to make it easier?
You should use a gem like YamlDB. Install the Gem and then use the following rake tasks
rake db:data:dump
RAILS_ENV=production rake db:data:load
The first command dumps the contents of dev database to a file called db/data.yml
Also, please remember that this must be used in addition to rake db:schema:dump|load tasks as this only ports the data assuming the schema is already in place
Assuming your database configurations are properly set up in config/database.yml, the following should get the database structure set up in production for you.
Runs against development database by default:
rake db:schema:dump
Run this against your production database by virtue of the RAILS_ENV environment variable:
rake RAILS_ENV=production db:schema:load
How to do?
I tried something like:
RAILS_ENV=production rake db:create db:load
in file /lib/tasks/load_tasks.rake and this file I tried in terminal as rake db:migrate, but I am getting errors about syntax etc.
I entered into terminal this command (I saw it in tutorial):
rails generate scaffold Account user_name:string description:text premium:boolean \
income:integer ranking:float fee:decimal birthday:date login_time:time
And this made me file 20110518181941_create_accounts.rb
How can I create database table - I thought the command above will create me database in mysql... I am now a bit confusing, what to do?
Which rule is playing here rake db:migrate?
I think you are getting this error because your syntax is wrong, please put && between sentences:
RAILS_ENV=production rake db:create && db:schema:load
or do it in separated lines
RAILS_ENV=production rake db:create
RAILS_ENV=production rake db:schema:load
the first command will create the database, the second command will Load the db/schema.rb file into the database
And finally you need to run your migration:
RAILS_ENV=production rake db:migrate
to create your Accounts table.
BTW if you run:
rake -T
you can see the list of rake tasks and their descriptions.
Hope this helps.