Frank Burleigh
2006-Jun-24 23:24 UTC
[Rails] Why is rails using DB objects that don''t exist?
I admit it--I''m newb right now. But only to rails, ruby and friends. I''m walking through a "recipe" tutorial but have been stuck for hours; it''s time to ask for help. On Windows I''ve got the latest ruby, rails, and webrick; I''ve got the Oracle OCI "thing" to talk to our Oracle 10g database, I''ve got Slick Edit and a command line. I''ve created a recipes table, a sequence to feed its ID primary key column, and a trigger that gets fired before record creation. I can use sql at a command line in Oracle''s sqlplus to add records. No sweat. But in the browser I get: ActiveRecord::StatementInvalid in RecipeController#create OCIError: ORA-02289: sequence does not exist: select recipes_seq.nextval id from dual I did once have a sequence with that name, but that''s long gone. In fact I''ve dropped and recreated the table, sequence and trigger several times with new names (except I continue using "recipes" for the table name). I''ve closed and opened and closed firefox. I''ve restarted webrick. I''m having trouble imagining what''s up--because I believe this little ruby app isn''t looking into the details of how an incrementing field works. There are clearly remnants somewhere, I just can''t find them. WTF?! Thanks anyone for getting me back on track. -- Posted via http://www.ruby-forum.com/.
Jodi Showers
2006-Jun-24 23:33 UTC
[Rails] Why is rails using DB objects that don''t exist?
Although I''m not using oracle, I suspect that rails is using standardized names to generate the sql to generate the recipe PK. ..so I''d suggest creating a sequence "recipes_seq" - rails likely takes table name + ''_seq'', and runs your quoated sql to obtain a pk before doing an insert into recipes. Jodi On 24-Jun-06, at 7:24 PM, Frank Burleigh wrote:> I admit it--I''m newb right now. But only to rails, ruby and friends. > I''m walking through a "recipe" tutorial but have been stuck for hours; > it''s time to ask for help. On Windows I''ve got the latest ruby, > rails, > and webrick; I''ve got the Oracle OCI "thing" to talk to our Oracle 10g > database, I''ve got Slick Edit and a command line. > > I''ve created a recipes table, a sequence to feed its ID primary key > column, and a trigger that gets fired before record creation. I > can use > sql at a command line in Oracle''s sqlplus to add records. No sweat. > But in the browser I get: > > ActiveRecord::StatementInvalid in RecipeController#create > > OCIError: ORA-02289: sequence does not exist: select > recipes_seq.nextval > id from dual > > I did once have a sequence with that name, but that''s long gone. In > fact I''ve dropped and recreated the table, sequence and trigger > several > times with new names (except I continue using "recipes" for the table > name). > > I''ve closed and opened and closed firefox. I''ve restarted webrick. > > I''m having trouble imagining what''s up--because I believe this little > ruby app isn''t looking into the details of how an incrementing field > works. There are clearly remnants somewhere, I just can''t find them. > > WTF?! > > Thanks anyone for getting me back on track. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Frank Burleigh
2006-Jun-25 00:38 UTC
[Rails] Re: Why is rails using DB objects that don''t exist?
Jodi Showers wrote:> Although I''m not using oracle, I suspect that rails is using > standardized names to generate the sql to generate the recipe PK. > > ..so I''d suggest creating a sequence "recipes_seq" - rails likely > takes table name + ''_seq'', and runs your quoated sql to obtain a pk > before doing an insert into recipes. > > JodiThat makes outstanding sense. I have written pretty much *no* code so I''m clueless what the sql looks like. Is there a means for me to see that? That would make this less magical, but also more comprehensible. ;-) And thanks for your reply. -- Posted via http://www.ruby-forum.com/.
Mike Harris
2006-Jun-25 00:53 UTC
[Rails] Re: Why is rails using DB objects that don''t exist?
Frank Burleigh wrote:> Jodi Showers wrote: >> Although I''m not using oracle, I suspect that rails is using >> standardized names to generate the sql to generate the recipe PK. >> >> ..so I''d suggest creating a sequence "recipes_seq" - rails likely >> takes table name + ''_seq'', and runs your quoated sql to obtain a pk >> before doing an insert into recipes. >> >> Jodi > > That makes outstanding sense. I have written pretty much *no* code so > I''m clueless what the sql looks like. Is there a means for me to see > that? That would make this less magical, but also more comprehensible. > ;-) > > And thanks for your reply.http://api.rubyonrails.com/ Rails, by default, guesses at the name of the sequence, as described by the previous replier. To set the name of the sequence class Recipe< ActiveRecord::Base set_sequence_name "recipeseq" # default would have been "recipe_seq" end Rails uses conventions for a lot of these things, such as table names, column names, sequences, etc. If you name your things like Rails expects, you don''t ahve to do anything else. However, if you don''t, that''s not a problem. You just have to tell rails what they are called. For a class Recipe, rails assumes the tables name is loads. For all tables, it assumed the primary key is a column called id. However, you can tell it differently. Class Recipe < ActiveRecord::Base set_table_name "recipe" set_primary_key "recipe" end If your table was recipe with a primary key called recipe, you can just tell it that. That''s what I do to use ActiveRecord with the database for a project at work, where the schema is 10 years old and pre-existing. -- Posted via http://www.ruby-forum.com/.
Mike Harris
2006-Jun-25 00:55 UTC
[Rails] Re: Why is rails using DB objects that don''t exist?
Frank Burleigh wrote:> Jodi Showers wrote: >> Although I''m not using oracle, I suspect that rails is using >> standardized names to generate the sql to generate the recipe PK. >> >> ..so I''d suggest creating a sequence "recipes_seq" - rails likely >> takes table name + ''_seq'', and runs your quoated sql to obtain a pk >> before doing an insert into recipes. >> >> Jodi > > That makes outstanding sense. I have written pretty much *no* code so > I''m clueless what the sql looks like. Is there a means for me to see > that? That would make this less magical, but also more comprehensible. > ;-) > > And thanks for your reply.Agile Web Development with Rails is the gold standard for Rails books. It''s absolutely outstanding, and in addition to being tremendously informative, it''s also fairly interesting to boot. If you are doing any Rails work at all, it''s a non-optional purchase. http://www.pragmaticprogrammer.com/titles/rails/index.html -- Posted via http://www.ruby-forum.com/.
Jodi Showers
2006-Jun-25 01:23 UTC
[Rails] Re: Why is rails using DB objects that don''t exist?
you can see the sql, as it runs, in the log/development.log. (useful for tuning as well) As noted, the books are really worthwhile. AWD, recipes, etc. have fun! Jodi On 24-Jun-06, at 8:38 PM, Frank Burleigh wrote:> Jodi Showers wrote: >> Although I''m not using oracle, I suspect that rails is using >> standardized names to generate the sql to generate the recipe PK. >> >> ..so I''d suggest creating a sequence "recipes_seq" - rails likely >> takes table name + ''_seq'', and runs your quoated sql to obtain a pk >> before doing an insert into recipes. >> >> Jodi > > That makes outstanding sense. I have written pretty much *no* code so > I''m clueless what the sql looks like. Is there a means for me to see > that? That would make this less magical, but also more > comprehensible. > ;-) > > And thanks for your reply. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails