Home › Forums › Persistent Login › Another solution to the SQL foreign key problem
Tagged: mysql error
This topic has 3 voices, contains 11 replies, and was last updated by Manuel Freiholz 84 days ago.
| Author | Posts |
|---|---|
| Author | Posts |
| January 29, 2012 at 2:04 pm #643 | |
|
timeggleston |
The error described here, where you get an error like:
upon creating the auth_tokens table, can also be caused by mismatched table engines. The auth_tokens table is created using the InnoDB engine. After a lot of troubleshooting, I discovered that I was getting this error because my “users” table from the main Roundcube installation was using the MyISAM engine. The current Roundcube SQL initialisation script uses InnoDB, so this must be an upgrade hangover from an old version. The solution was simply to recreate the users table as InnoDB and re-load the data. |
| February 19, 2012 at 3:38 pm #646 | |
|
Eric Westphal |
I get this error too, but my maildb users table doesn’t have a `user_id` INT(10) UNSIGNED field–it has a `id` VARCHAR(255) field instead for its primary key. I tried a few modified versions of this table but nothing quite seemed to work. Any suggestions for how I modify the mysql.sql query to create a table that will work? Thanks in advance! |
| February 20, 2012 at 8:10 pm #647 | |
|
Manuel Freiholz |
Hi, did you try to change the “user_id” field type to VARCHAR? By the way… Is it possible that the user’s ID contains a “:” sign? |
| February 22, 2012 at 5:25 am #648 | |
|
Eric Westphal |
Hi, I modified the mysql.sql script as follows (both changing user_id to type VARCHAR(128) and changing the referenced key in the users table):
ALTER TABLE `auth_tokens` and the error I get is ERROR 1005 (HY000): Can’t create table ‘maildb.#sql-25a_1a7cc’ (errno: 150) All of my tables except auth_tokens are driven by MyISAM. Perhaps it’s just my lack of in-depth knowledge of MySQL, but I’m concerned that changing the engine on the tables in a working system will cause something to break elsewhere. Is the only solution to change the engine for my other tables? Thanks for your response! |
| February 22, 2012 at 6:26 am #649 | |
|
Manuel Freiholz |
Hi,
or just remove the “ENGINE=XXX”. |
| February 23, 2012 at 7:08 am #650 | |
|
Eric Westphal |
You’re right, Manuel, that’s the obvious thing to try! I assumed there was a reason why it needed to be InnoDB since it was explicitly specified. Indeed, when I try leaving out the ENGINE argument, the table is created (and I can see that it is MyISAM) and altered without a problem. However, even after copying the config.inc.php.dist to config.inc.php, turning if_pl_use_auth_tokens on, and restarting apache, the persistent login doesn’t work: when logging out, logging back in again, closing and re-opening my browser, I get a message “Invalid request! No data was saved” and am dumped back to the login screen. All this time, the auth_tokens table remained empty. It worked, of course, with the UserData cookies. So does this mean that InnoDB is the required engine, or is it perhaps something else? I’ll do more investigation later, unless you have any ideas. |
| February 23, 2012 at 5:17 pm #651 | |
|
Eric Westphal |
I have also changed the DEFAULT CHARSET to Latin1, which is what my users table uses (for whatever reason). That didn’t do it either. I have been unable to verify that the constraint was in fact added: SHOW TABLE STATUS FROM maildb; does not show any constraints on auth_tokens, but there were no errors when I executed the line to add the constraint, so I assumed it was actually added. I don’t think that MyISAM tables support foreign key constraints, so this is probably why InnoDB was specified. |
| February 24, 2012 at 11:16 am #652 | |
|
Manuel Freiholz |
Still no logs in /var/log/apache/error.log or the Roundcube’s log folder? I will try it on my own at the weekend to find a general approach for this case. |
| February 26, 2012 at 8:29 pm #653 | |
|
Eric Westphal |
Ah hah! I wasn’t aware of the roundcube log folder. Here’s a very interesting snippet from roundcube/logs/errors: [26-Feb-2012 20:20:10] MDB2 Error: no such table (-18): _doQuery: [Error message: Could not execute statement] [26-Feb-2012 20:20:10 +0100]: DB Error: MDB2 Error: no such table Query: _doQuery: [Error message: Could not execute statement] [Last executed query: INSERT INTO auth_tokens (`token`, `expires`, `user_id`, `user_name`, `user_pass`) VALUES ('1330284010-tUjH2QyTPLNhfwGyriLJtblablabla', '2012-02-29 20:20:10', '15', 'eric@blablabla.com', 'ltGPHsyyrVF6U7ICbYWVbTryUdsnblabla')] [Native code: 1146] [Native message: Table 'roundcubemail.auth_tokens' doesn't exist] in /var/www/roundcube/program/include/rcube_mdb2.php on line 717 (POST /?_task=login&_action=login) So it’s trying to write to a roundcubemail database, but I don’t have such a database. My `users` table is in a database named just “mail”. |
| February 26, 2012 at 8:40 pm #654 | |
|
Manuel Freiholz |
Ah okay.. |
| February 26, 2012 at 8:58 pm #655 | |
|
Eric Westphal |
Thanks, Manuel. With clues from you I solved it, and it’s working at last! My misunderstanding was that I was creating the auth_tokens table in my main maildb database: I didn’t know that there was a roundcubemail database and that this was where I should create the new table. The roundcubemail database uses InnoDB for all tables, not MyISAM, so I was able to create the table with foreign key exactly as specified in the mysql.sql script. Perhaps just a one-liner in the http://www.insanefactory.com/roundcube-persistent-login-plugin/ page in the AuthToken Cookie section, such as specifying the roundcubemail database in the “It requires the creation of a table in your roundcubemail database as well. ” sentence, would prevent such confusion (though perhaps it’s mainly due to my ignorance of roundcube). |
| February 26, 2012 at 9:02 pm #656 | |
|
Manuel Freiholz |
I’m glad to hear that i finally works for you. |
You must be logged in to reply to this topic.