Mysql::Error: You have an error in your SQL syntax;

help!

rake db:migrate (in /var/www/jabber) rake aborted! Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version forthe right syntax to use near '-items' at line 1: SHOW FIELDS FROM disco-items

(See full trace by running task with --trace)

I think you need to not use hyphens in your table names.

Julian.

Julian Leviston wrote:

I think you need to not use hyphens in your table names.

Julian.

Thanks Julian, I just figure that out when I dump the DB to a test and after erasing that table it got stuck on another one with hyphens ... but the issue here is that this is not a DB I created for my application, instead is an already DB used by jabberd2 and I wanted to create a front end on RoR.. so the question is.. is there a way to make this work? alias? using the models? help!! :-/

Can you show us your model?

Learn about Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) http://sensei.zenunit.com/

Rek,

One way you could probably get around it is to explicitly put quotes around the table name. It's been a while since I've had to worry about weird table names, but either single quotes or backticks should work. Or maybe try escaping the hyphen, although that seems to me less likely (but worth a quick try).

-Danimal

Julian Leviston escribió:

Can you show us your model?

Learn about Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) http://sensei.zenunit.com/

Hi Julian, I have no models so far.. I was going to start this project and got into that error a couple days a go and I am going nuts.. first I was trying to see if I could modify the db table names but looks like jabberd2 has this hardcoded :frowning: so basically I created the project.. and when a head to tell rails about my db when I got into this mess.

if it helps how the jabberd2 db schema is here is a link In this link below almost at then end it shows the mysql Schema they use and I have. http://jabberd2.xiaoka.com/wiki/InstallGuide/Jabberd2Architecture

Um.... I don't understand how you're getting that error if you have no
models...

Julian.

Julian Leviston escribió:

Um.... I don't understand how you're getting that error if you have no models...

hmm let me explain what I have done..(excuse me for my bad english)

I have a DB that use for my jabberd2 server with around 2000 users and very populated.. I created a backup a username/password for that db for rails to use.. then I created the rails project rails --database=mysql(or something like that)lol then I put the DB info on config/datatabase.yml and after this step if I am using an inheritage DB I run rake db:migrate to create a scheme under db/schema.. not sure if this is the right thing to do.. so far it has worked fine if the DB was friendly to rails. so I get the error right there.. when I run rake db:migrate and the rails db scheme gets only populated till I get the error.. then drops. :frowning:

Thanks for the help. I have the feeling I am going to learn something I din't know about inheritage DB's

Ah.

Rails won't automatically create a schema for you, unless you define
some models.

For instance, if you have a table called users, and the table name is
users, add this model to your models folder

file name: users.rb

class User < ActiveRecord::Base end

You don't need to run rake db:migrate unless you want to do a
migration (ie execute some code that does some stuff to the database).
You can probably get around using hyphenated names by using table_name
'whatever-hyphenated-table-name' like that under the beginning of the
class. (I think that's the right syntax).

Each model you have (one per table) will wrapper a table.

Julian.

Learn about Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) http://sensei.zenunit.com/

Julian Leviston escribió:

Ah.

Rails won't automatically create a schema for you, unless you define some models.

For instance, if you have a table called users, and the table name is users, add this model to your models folder

file name: users.rb

class User < ActiveRecord::Base end

You don't need to run rake db:migrate unless you want to do a migration (ie execute some code that does some stuff to the database). You can probably get around using hyphenated names by using table_name 'whatever-hyphenated-table-name' like that under the beginning of the class. (I think that's the right syntax).

Each model you have (one per table) will wrapper a table.

Julian.

ohhh, this makes much more sense now.. in the book I read and the howtos it always ask you to create the DB and of course then comes db:migrate so I have always used that way !! :-/ ok so in my particular case you are telling me to create the class like:

class Disco-items < ActiveRecord::Base

but what for the purpuse of learning what if I did wanted to add something to the DB down the road.. how will I tell/force Rails to use disco-items or make disco-items appear to ruby as Disco_items on the application with out changing the table name in the DB?

Thanks so much this clears a lot of things.

I'd prefer

class DiscoItems < ActiveRecord::Base table-name 'disco-items' end

Julian Leviston wrote:

I'd prefer

class DiscoItems < ActiveRecord::Base table-name 'disco-items' end

thank you!! this works!! YEAY!