Storing data in sessions with mysql2 database - mysql

I developed a ruby on rails 3 web app, and i had originally depended on a sqlite3 database that was locally stored in my computer before deploying it. I stored certain information in the sessions to get certain part of my web app to work.
However after deploying, i decided to use a mysql2 database from xeround.com and my website broke down. At first I had gotten an error message saying that i did not have a sessions table in the database. So I created a sessions table. And now it says
ActiveRecord::StatementInvalid in ClientController#index
Mysql2::Error: Unknown column 'sessions.session_id' in 'where clause': SELECT `sessions`.* FROM `sessions` WHERE `sessions`.`session_id` = '................' LIMIT 1
Would i have to create the appropriate columns manually in the new sessions table that I made in the mysql2 database? Or is there another way to get around it?

What seems to be missing is session_id do check in your table sessions does it have column named session_id in it? if it is not there then create it through a migration. According to me, you should not do anything manually cause, in future if you wants to make some changes or rollback the tables you might face some issues.

Related

MySQL can't show table after altering auto_increment

I created two tables like this
and I want to change the added data's id so I use
alter table member auto_increment=5;
after this, it couldn't show my member table. It shows
error 2013: lost connection to MySQL server during query.
I thought my table is too big to run, so I changed the limit and the DBMS time out, but it didn't work either. Can someone tell me what's the problem now?
I found the problem. Don't edit your MySQL database when you're connecting it with your Python Flask program. Edit means any CRUD actions.

Deleting a table from MySQL database in Django manually

During my experimentation with my blog app (blogapp) in Django, I created two models (Category and Language), connected them to another model (Post) using following connections:
category = models.ManyToManyField(Category)
language = models.ForeignKey(Language)
Then it gave an error like THIS due to the lack of default value. Tried to roll that back by using an amalgam of THIS and THIS. Then I tried to add a default value using THIS. I've got an error "django.db.utils.OperationalError 1050, Table XXX already exists", then I tried THIS. Tried to revert back migrations by deleting the created migrations from the migrations folder manually. At some point I got django (1054, "Unknown column in 'field list") error.
Finally I decided to revert back to my original starting place. When I connect to my MySQL database using python manage.py dbshell, I realized that my MySQL server still have two tables that should have been deleted, blogapp_category and blogapp_language. Server is working properly but I keep getting "Table XXX already exists" error when I try to add those models.
Dropping tables from MySQL seems to be the only option at the moment.
When I run
mysql> SHOW COLUMNS FROM blogapp_post;
I did not see any reference to language or category, i.e. no columns named language_id or category_id. I have two questions at the moment:
Is it safe to delete tables manually using:
DROP TABLE blogapp_language;
DROP TABLE blogapp_category;
Will there be any negative effects?
Is there a way to freeze database like git so that when I revert to the old database, such tables added to the database by django migrations automatically dropped??
Delete respective entry from table django_migrations.
Delete migration folder from your app.
Delete table created by the app.
Now do makemigrations and migrate.
You can revert back using git but there will be errors and data correction requirements.

Wordpress - Is there a way to recover the table wp_term_relationships?

I'm trying to help a Non-Profit Organization with their site (which is built with Wordpress) that suddenly became "buggy"/odd: menus were missing, categories were empty, etc.
I'm no expert around Wordpress, so the first thing I did was to turn on the DEBUG mode and I get this message:
Error en la base de datos de WordPress:
[Table 'racidb.rc_term_relationships' doesn't exist]
So, next thing I did was check on the database (MySQL). When I login on phpMyAdmin, I can see the table on the left column but when I try to browse the content, I get this message error:
#1146 - Table 'racidb.rc_term_relationships' doesn't exist
I tried to repair the table, drop it and delete it's content with no luck. I keep getting the error #1146.
Unfortunately, there are no backups on the database so I just can't upload the table again.
According to them, the error happened at the same time in which Wordpress was updated to 4.2.6 (they got the automatic email of Wordpress the day this issue appeared).
My questions:
1) Does anyone know what might have happened?
2) Is there any way I can recover the data from MySQL?
3) Is there any way to recover the table "xx_term_relationships"? Besides creating manually all the records.
Many thanks in advanced!
Sorry for late response. But i had the same problem , my client website(WordPress) automatically gets updated.it was build on 3.2 version of WordPress.
Some of the tables gets corrupted and its appear in structures also in left side of tables.
To Solve This problem you need to repair your tables
Go to database > table structure.
Check the table which needs to repair.
select Repair Table from dropdown.

ActiveRecord::StatementInvalid: Mysql2::Error: Incorrect string value

Last night I witnessed something rather peculiar! I'd post a number of records like this one - with no problems at all; but suddenly my Rails app refused to INSERT a particular record into a particular table.
This gist details the result. You may learn that the abstract_mysql_adapter.rb does not allow the insert whereas the Rails dbconsole (really the mysql client) does indeed allow the insert?
Does anyone know what goes on? I for one is stumped :(

Is it possible "Database Synchronization"

I have a problem and not sure if this is possible. My web application has a database and i'm using a mysql workbench and using wamp server.
My web app has a database name healthcare, and if I import again another database with the same tables, etc but addition data. I want the first database to be updated only with new values but not replaced.
Is it possible?
Edit: I searched in the net and other related sources and I manage to set my phpmyadmin "Ignore multiple statement errors". When I import the second database (.sql with same tables but with new data) it does not update the first database but the message is successful. Please help, I'll appreciate any help...
in the past ive searched for tools to do some similar database sync tasks - in my experience ive found that none are free & reliable.
have you tried writing some queries to do this manually?
first thing that comes to mind would be figuring out a key you can use to evaluate each row and determine if you should copy said record from database A to database B.
afterwards you could simply do an INSERT(SELECT)
INSERT INTO healthcare_DESTINATION.table (SELECT * FROM healthcare_SOURCE WHERE some_condition = 1);
obviously this is the simplified version - but i've done something very similar utilizing timestamps (eg only copy rows newer than the newest row in the destination table)
hope this helps