# Strange mysql problem

**URL:** <https://www.ruby-forum.com/t/strange-mysql-problem/58339>\
**Category:** Rails\
**Created:** [April 20, 2006, 6:16pm UTC](https://www.ruby-forum.com/t/strange-mysql-problem/58339 "2006-04-20T18:16:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![travis\_laduke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e95f7d/32.png) [@travis\_laduke](https://www.ruby-forum.com/u/travis_laduke)\
**Post date:** [April 20, 2006, 6:16pm UTC](https://www.ruby-forum.com/t/strange-mysql-problem/58339/1 "2006-04-20T18:16:09Z")

</div>

i have this model:

class LineItem \< ActiveRecord::Base  
belongs\_to :quote  
end

in the console:

> > l = LineItem.create  
> > ActiveRecord::StatementInvalid: 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 ’ , , , )’ at line 1:  
> > INSERT INTO line\_items (`qty`, `quote_id`, `price`, `lead_time`,  
> > `part_number`) VALUES(, , , , )

why is it doing that? all my other models that belong\_to something  
work.

---

<div class="post-metadata">

**Author:** ![travis\_laduke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e95f7d/32.png) [@travis\_laduke](https://www.ruby-forum.com/u/travis_laduke)\
**Post date:** [April 20, 2006, 6:22pm UTC](https://www.ruby-forum.com/t/strange-mysql-problem/58339/2 "2006-04-20T18:22:21Z")

</div>

* * *

Rails mailing list  
removed\_email\_address@domain.invalid  
[http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

---

<div class="post-metadata">

**Author:** ![travis\_laduke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e95f7d/32.png) [@travis\_laduke](https://www.ruby-forum.com/u/travis_laduke)\
**Post date:** [April 20, 2006, 6:27pm UTC](https://www.ruby-forum.com/t/strange-mysql-problem/58339/3 "2006-04-20T18:27:34Z")

</div>

travis laduke wrote:

> i have this model:
> 
> class LineItem \< ActiveRecord::Base  
> belongs\_to :quote  
> end
> 
> in the console:
> 
> > > l = LineItem.create  
> > > ActiveRecord::StatementInvalid: 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 ’ , , , )’ at line 1:  
> > > INSERT INTO line\_items (`qty`, `quote_id`, `price`, `lead_time`,  
> > > `part_number`) VALUES(, , , , )
> 
> why is it doing that? all my other models that belong\_to something  
> work.

[http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html](http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html)

With such an association, you need to have an instance of a Quote object  
to properly create a LineItem.

some\_quote = Quote.find(some\_id)  
some\_quote.line\_items.create

---

<div class="post-metadata">

**Author:** ![travis\_laduke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e95f7d/32.png) [@travis\_laduke](https://www.ruby-forum.com/u/travis_laduke)\
**Post date:** [April 20, 2006, 7:08pm UTC](https://www.ruby-forum.com/t/strange-mysql-problem/58339/4 "2006-04-20T19:08:37Z")

</div>

> > q = Quote.find :first  
> > =\> #\<Quote:0x257af14 @attributes={“status”=\>“quoted”,  
> > “created\_on”=\>“2006-04-19 21:52:40”, “follow\_up\_on”=\>“2006-04-26  
> > 21:52:40”, “updated\_on”=\>“2006-04-19 22:30:23”, “id”=\>“6”,  
> > “rep”=\>“travis”, “referred\_by”=\>“mectronic”, “person\_id”=\>“4”}\>
> 
> > q.line\_items.create  
> > ActiveRecord::StatementInvalid: 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 ‘’ at line 1: INSERT  
> > INTO line\_items (`qty`, `quote_id`, `price`, `lead_time`,  
> > `part_number`) VALUES(#Quote:0x256c7fc, #Quote:0x256aba0, #\<Quote:  
> > 0x256aba0\>, #Quote:0x256aba0, #Quote:0x256aba0)

strange?

---

<div class="post-metadata">

**Author:** ![travis\_laduke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e95f7d/32.png) [@travis\_laduke](https://www.ruby-forum.com/u/travis_laduke)\
**Post date:** [August 3, 2006, 2:22pm UTC](https://www.ruby-forum.com/t/strange-mysql-problem/58339/5 "2006-08-03T14:22:04Z")

</div>

doh!  
now how would I go about migrating to a different model and table name?

---

<div class="post-metadata">

**Author:** ![travis\_laduke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e95f7d/32.png) [@travis\_laduke](https://www.ruby-forum.com/u/travis_laduke)\
**Post date:** [April 20, 2006, 7:08pm UTC](https://www.ruby-forum.com/t/strange-mysql-problem/58339/6 "2006-04-20T19:08:39Z")

</div>

Hey,

quote() is a method in ActiveRecord, perhaps that’s the source of  
your problem?

## Regards, Trevor

Trevor S.  
[http://somethinglearned.com](http://somethinglearned.com)
