When building a model with a ruby \u200b\u200bon rails migration create a table in the database. The name of this table is equal to the pluralized form of the name model. In MySQL this migration will generate a sql statement of the form:
model_name_pluralized CREATE TABLE (`id` int (11) DEFAULT NULL auto_increment PRIMARY KEY, `created_on
As you can see, the column names are quoted but not named in the table. If using as a model name in the singular form of a MySQL reserved word, the migration will generate a sql statement that will fail as
Mysql:: Error: You have an error in your SQL syntax; check the manual That corresponds to your MySQL server version for the right syntax to use near 'databases (`id` int (11) DEFAULT NULL auto_increment PRIMARY KEY , created_on `da`' at line 1: CREATE TABLE databases (`id` int (11) DEFAULT NULL auto_increment PRIMARY KEY , `created_on` date DEFAULT NULL, `name` varchar (255)
DEFAULT NULL) ENGINE = InnoDB
Last week I read about Josh Susser
transparencies
(
Laying Tracks
) who encouraged me to write a patch for this problem. Before writing anything looked if I could find something related. I found a similar ticket on the Rails trac :
# 7850 [PATCH] Added missing backticks to mysql adapter
- # 4905 [PATCH] Rails Should backtick table names automagically
- # 3631: table names Should Be quoted
- # 1633: [PATCH] quote_column_name in ActiveRecord:: ConnectionAdapters ...
- The ticket most interesting of these is # 4905, where all sentences are corrected MySQL that can generate this error. Do not know why but this patch is not included in the rails code despite being the May 25, 2006. The tickert # 7850 is considered closed to doubled over the # 4905. And the history of ticket # 3631 ends with the phrase "do not use reserved words" which in my opinion is not the best solution. In short, the problem there (can not create models with names like "database", "exist", etc ...) and the patch also exists (# 4905). Entoces, to do now to fix this problem?
0 comments:
Post a Comment