So I created a db with 'sqlite development'. I then ran 'rake db:setup' and it seemed to execute without error. However when I launch the sqlite console, I can't seem to find any of the tables within the development database. Maybe I'm not accessing the database correctly? Any ideas?
Have you done rake db:create? I using that command to create the databases, not manually add the databases.
copied from comment section
Related
Everything was working fine yesterday and all of a sudden when i tried to run my server or run any rake tasks i get this error
Mysql2::Error: Table 'myapp_development.key_value_stores' doesn't exist: SHOW FULL FIELDS FROM `key_value_stores`
I've tried google searching and searching on stackoverflow all morning and cant find a solution to this
Try to rollback your migration file (take backup of the migration file will help while creating new ),
rake db:migrate:down VERSION=migrations's_version
and then try to restart the rails server.If you face same problem then with same migration number search in schema_migrations table in database delete that record and make new migration again.
I was struggling with this for a while but what i ended up doing
update xcode and update command line tools
uninstall then install mysql via homebrew
then i ended up manually removing my database folder in
usr/local/var/mysql/myapp
then i did a
rake:create
and then i just pulled my production database and copied it to my development database
rake db:backup_and_load
then I was up and running again
dont know which one of that fixed it specifically but thats what i did
How can I insert new records to Heroku database. I have successfully uploaded my application and database structure. Now I need to insert some records so it could work. I tried to use seeds.rb but without any success. db:push and db:seed don't give any success. The database is always empty. Is there any heroku tool available which I could use to see database structure and insert data?
Thank you.
You have a few options. You can run heroku run rake db:seed.
Or assuming Postgres, try
heroku pg:psql
And run your SQL commands from there. See here for more.
I was also able to connect my IDE to my databases on Heroku. I am using RubyMine, so it was a matter of using the right JDBC URL to make that happen.
You can use below command for insert record to Heroku server
heroku run rails c
Example:-
suppose you have one table is employee and field are first_name.
Now open a command line and call this command
heroku run rails c
After call insert command
Employee.create(first_name: "admin")
I just deployed my rails app to a Linode VPS, and was wondering what would be the best way of adding records to the DB.
I have tables such as Categories, which I'd like to populate.
I thought of the Taps gem, using a csv, or an sql dump file.
I'd like to know if there are any tools out there for this?
Thanks
For this puporse there are the so called seed file which is default in:
db/seeds.rb
You can add entries here ( there is an example in the seed file ), which you can generate after deployment with a rake task:
rake db:seed
You probably are using bundler as well, so use:
bundle exec rake db:seed
In case of large number of seeds you can always create multiple files, see this blogpost about handling large seed files.
However, if you are in a state, where the already existing data in the app is crucial and you are changing servers or database drivers you wanna take a look on yaml_db gem which gives a nice method to abstract the existing data away from your actual db driver and export it into a .yaml file which you can import later back e.g.: after deploying on a new server.
See Railscast - #179 about seeding.
The rails way would be to use seed data in db/seeds.rb and then populate it by using rake db:seed.
You could also use a sql dump file and restore by issueing mysql -u <user> -p <database_name> < <mysql_dump_file>
The Easy Reference Data gem is similar to db:seed, but will update records if entries already exist. It also has easy integration with Capistrano.
Full disclosure: The company I work for developed the gem.
I have a production.sqlite3 file which I want to import its data to the current rails project, the database schema is match between the file and my current project. I did copy the content to the development.sqlite3 file but this does not work. The only way I know to insert data to the database is by loading some yml file or use the seed command. Is there any magic command or other ways to let the rails loading the data from .sqlite file? Because from what I disover, the behavior of rails is that it only creates the .sqlite3 file when you do rake db:create &migrate, but it will ignore what ever manual changes happen in that file. Please help!
It looks like renaming your .sqlite3 file should work. Make sure you have restarted your server, and that the server is running in the correct environment. If you move both the .sqlite3 files into a completely different folder, and restart the server, an error should occur. If it doesn't, your server didn't properly restart - kill all ruby processes and try again.
In answer to your question about migrating data, I had a similar problem recently, where I had to migrate from sqlite3 to mysql. Best solution I found was yaml_db. It seemed to do the job beautifully - add it to the project, then do
rake db:data:dump
Swap the database configurations (or migrate a new database file, or change your development environment, whatever it is you need to do to make an empty but structured database active), then:
rake db:data:load
I'm trying to install a software called Teambox in my Dreamhost shared account, following these instructions.
I have no experience with Rails. I just want to install the software in the shared hosting.
In this shared hosting, all dependencies are ok, but I have to create the dabatase from their panel. I can't create in command line (ssh).
So, when I run "rake db:create" these's an error, because the db already exists (because I created in panel).
I've already contacted support. They can't change this policy.
How do I populate my tables "by hand" in this case? Which files should I look inside Teambox's folder...
Thanks!
rake db:create should create your database and that's all. It doesn't creates your tables.
There are several rake tasks to do that :
rake db:migrate which will execute your migrations. So create all your tables.
rake db:seed which will add the original data of your application. See Database Seeding
You don't need to be able to create the database to do any of these.