ccherlet-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Oct-25 17:41 UTC
can''t get line_items table created
I try to execute this script on Mysql and it can''t create it and get this error in MySQL query browser window. "Can''t create table ''.\pos_development\line_items.frm'' (errno: 150)" The problem is with the "constraint fk_items_product" part of the script. Help!!! create table line_items ( id int not null auto_increment, product_id int not null, quantity int not null default 0, unit_price decimal(10,2) not null, constraint fk_items_product foreign key (product_id) references products(id), primary key (id) ); --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Try changing the order in which you''re creating the tables. hth, Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
ccherlet-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> I try to execute this script on Mysql and it can''t create it and get > this error in MySQL query browser window. > "Can''t create table ''.\pos_development\line_items.frm'' (errno: 150)" > > The problem is with the "constraint fk_items_product" part of the > script.Checking the documentation here: http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html ... it looks like "constraint" isn''t valid syntax within the table definition (and constraints don''t actually get names like fk_items_product). Your table definition should look like: CREATE TABLE line_items ( id INT NOT NULL AUTO_INCREMENT, product_id INT NOT NULL, quantity INT NOT NULL DEFAULT 0, unit_price DECIMAL(10,2) NOT NULL, FOREIGN KEY (product_id) REFERENCES products(id), PRIMARY KEY (id) ); I haven''t tried this myself (I''m using PostgreSQL), but it looks right according to the docs. (If it doesn''t work, hopefully that page should help you out further.) Having said that, you really should look into using migrations to define your database rather than creating it directly with raw SQL. They''re more flexible, easier to work with, database-independent, and are currently considered the correct, "modern" way to define a Rails database schema. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---