hi everybody i'm new to Ruby on Rails...
I created a Rails Application for that i created a database called 'cart' in MySQL database by using rake command. but unfortunately my database got crashed. right now there are no databases including older ones also deleted.
please help me, how can i get my all databases from MySQL s/w. is there any command to restore the crashed data.
Thanks
If you don't have backup it could be hard. You can remove database, create another and rake db:migrate but it will only create a structure for you and will not restore data.
You can try to reproduce your records from rails logs but it will be a lot of work
What do you mean by database crashed?
Related
I have a problem when I backup my database from old server to the new one. Both run Ubuntu. The difference is the old database is using phpmyadmin 1.6.3 and the new one is 5.7.21. I lost some tables but it appear in the sidebar. Can anyone describe to me what is going on with my db? Here is the screenshot.
to be clear, here is the screenshot of my old database phpmyadmin interface.
You may try stop and start the mysqld service.
If the error still exists then back up the database file and drop it then import again to a newly created database.
**commands may be OS specific
follow instructions from : MySQL Site
I have situation here, I have a database in production environment, and now I have to add few columns in table and drop 1 table from the database. I ran all the migrations such as rails g migration AddDeskToHelper desk:string and similar for dropping a table.
But now I want to upload this new generated schema into existing database without deleting any data from the database.
I'm searching about it and did not find any accurate answer.
For example, here
it says that rake db:schema:load deletes all the data from Database in production environment.
Kindly help me in this case.
If you have created the migrations to add some cols in existing tables or delete some tables, the rake db:migrate RAILS_ENV=production command will perform an "ALTER table..." without destroying your data, except you are dropping a col or table with data content.
But it's always recommended to perform a database backup before altering your production database.
I know this one sounds kind of backwards! I've been working on a cloud-based case-management application, and was working on a support-ticketing feature. We have our development database (MySQL) that has all the same data as our production database (It's a very large app). Development is basically a "sandbox" environment, hence why the development db has all the same as the production db. This morning, I ran into a problem in my local development server for:
Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=development' to resolve this issue.
Alright, did that, even though it didn't make any sense. It err'd out, because it was trying to create tables that already existed (I had already ran my migrations, the features were completed a day ago! And everything worked great).
The only thing that I did the moment before I got this message in my development server was uncomment an entirely-commented-out file to try and fix problems with TinyMCE (/config/tinymce.yml, text editor), followed by restarting my rails dev server. All this file was, was a bunch of defaults and plugins. When I saw the problem, I first commented them all back out. Still the same error. Proceeded with rake db: tasks.
Started looking for answers.. kept getting errors. Made a noob mistake, and ultimately did a
rake db:migrate:reset
which I knew would rebuild the schema at the cost of hosing the db. This failed.. But we do have the db in more than one place (since it's the same as production.) Also, just to try and bring all the tables back:
rake db:schema:load
....failed on one of the tables anyway with
ActiveRecord::StatementInvalid: Mysql2::Error: Specified key was too long; max key length is 767 bytes: CREATE UNIQUE INDEX `login` USING btree ON `users` (`login`, `intranet_id`)
..and all the tables are empty (as expected) that were successfully created. I'm by no means a database pro (I haven't dev'd very long). Am wondering, is there a way to copy the entire production database into the devel database? Tables, data, and all. Or any other suggestions? Really lost on this one.
You can use mysql_dump.
If you connect to the database everything is there - you just have to do a dump of the full database and then do the dump again into the production tables.
As you clearly see you can output from the database with ">" and you can import with the "<".
Using rails 3.2.8 ruby 1.9.3 p362.
There is something seriously amiss with my rails app. After so many db issues with an app, I STARTED FROM SCRATCH - read: rails new < new app name>
And started adding scaffolds and models. All in the past hour or so.
Then I tried to migrate a model called Product and I got the "Mysql2::Error: Table 'products' already exists" message when I ran rake db:migrate
Lo-and-behold my schema.rb file transformed itself into the mess of a file I had on my old app (on a different folder).
How can this happen? And how can I fix it?
Also, how often should I be pushing to git? I pushed once before building 2 new models and I already have a mess in my hands.
Help, please!
Did you clean up the old database for migrations from your older app / create a new database for the new app? Looks like it is the older database which is causing the issues.
You can go to your mysql prompt, and do a drop database database_name; and recreate an empty database using create database database_name.
I have created an app using a badly named database, all alterations to important data in the database have been done in fixtures so that I can just drop the database, recreate it and then rake migrate the database tables and fill them with the initial data from the fixtures.
I would like to change the name of my database now, so I updated the database.yml file to reflect another database name. I created the database in mysql and then tried to run the migration and fixtures.
Running the migration with trace shows that it is running commands to create tables etc. However once I am finished I get errors in my application saying that the tables don't exist in the new database.
I go into mysql and check the database and it is completely empty. I have tried wiping everything and running the migrations a few times but nothing changes. Is there something I am missing?
I don't know what commands you used to do the migration, but to migrate a production database (which I infer from the tag, "production-environment"), you have to do:
RAILS_ENV=production rake db:migrate
If that's not the answer, then please provide the command you used to perform the migration, which database you expected to be affected, and the relevant bits of database.yml.