I am new to rails and have come across a problem with a sample application I was working on. When trying to use rake migrate I got the error listed below. my db file contains the following class ContactDb < ActiveRecord::Migration def self.up create_table "people" do |t| t.column "id", :integer t.column "name", :string t.column "address", :string t.column "city", :string t.column "state", :string t.column "zipcode", :string end end def self.down drop_table :people end end and the error is: == ContactDb: migrating ======================================================-- create_table("people") rake aborted! 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 ''(11), `name` varchar(255) DEFAULT NULL, `address` varchar(255) DEFAULT NULL, `ci'' at line 1: CREATE TABLE people (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY(11), `name` varchar(255) DEFAULT NULL, `address` varchar(255) DEFAULT NULL, `city` varchar(255) DEFAULT NULL, `state` varchar(255) DEFAULT NULL, `zipcode` varchar(255) DEFAULT NULL) ENGINE=InnoDB I''m using a default install. I noticed that the value supplied to PRIMARY KEY was the number 11. Any suggestions. Thanks, Paul --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
On Tue, Apr 29, 2008 at 11:31 PM, Donald <dpsthree-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I am new to rails and have come across a problem with a sample > application I was working on. > When trying to use rake migrate I got the error listed below. > > my db file contains the following > > class ContactDb < ActiveRecord::Migration > def self.up > create_table "people" do |t| > t.column "id", :integerRails adds an id field for you, unless you tell it not to. So leave yours out. Also, you might check out the new column syntax for use with create_table. You can do less now: t.integer :name for example. -- Greg Donald http://destiney.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?hl=en -~----------~----~----~----~------~----~------~--~---
try it without id On Tue, Apr 29, 2008 at 10:31 PM, Donald <dpsthree-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I am new to rails and have come across a problem with a sample > application I was working on. > When trying to use rake migrate I got the error listed below. > > my db file contains the following > > class ContactDb < ActiveRecord::Migration > def self.up > create_table "people" do |t| > t.column "id", :integer > t.column "name", :string > t.column "address", :string > t.column "city", :string > t.column "state", :string > t.column "zipcode", :string > end > end > > def self.down > drop_table :people > end > end > > and the error is: > > == ContactDb: migrating > ======================================================> -- create_table("people") > rake aborted! > 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 ''(11), `name` varchar(255) DEFAULT NULL, `address` > varchar(255) DEFAULT NULL, `ci'' at line 1: CREATE TABLE people (`id` > int(11) DEFAULT NULL auto_increment PRIMARY KEY(11), `name` > varchar(255) DEFAULT NULL, `address` varchar(255) DEFAULT NULL, `city` > varchar(255) DEFAULT NULL, `state` varchar(255) DEFAULT NULL, > `zipcode` varchar(255) DEFAULT NULL) ENGINE=InnoDB > > > I''m using a default install. > > I noticed that the value supplied to PRIMARY KEY was the number 11. > Any suggestions. > > Thanks, > Paul > > > >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
It worked. Thanks! But out of curiosity what was wrong with the original setup? Does rails not support the addition of an id field without explicitly telling it not to add its own, or is there something else going wrong? thanks again --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Try leaving out the spec for the id column--rails will add that for you. Also--I don''t know if it matters (probably doesn''t) but if you''re using the current version of rails, there''s a new syntax for migrations. Here''s my create_people, FWIW: class CreatePeople < ActiveRecord::Migration def self.up create_table :people do |t| t.string :first_name, :null => false t.string :last_name, :null => false t.integer :organization_id t.string :personal_url t.string :voice_number t.string :cell_number t.string :email_address, :null => false t.date :birth_date t.text :notes end execute("alter table people add constraint fk_organizations foreign key (organization_id) references organizations (id)") end def self.down drop_table :people end end HTH, -Roy -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Donald Sent: Tuesday, April 29, 2008 9:32 PM To: Ruby on Rails: Talk Subject: [Rails] Beginner mysql problem I am new to rails and have come across a problem with a sample application I was working on. When trying to use rake migrate I got the error listed below. my db file contains the following class ContactDb < ActiveRecord::Migration def self.up create_table "people" do |t| t.column "id", :integer t.column "name", :string t.column "address", :string t.column "city", :string t.column "state", :string t.column "zipcode", :string end end def self.down drop_table :people end end and the error is: == ContactDb: migrating ======================================================-- create_table("people") rake aborted! 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 ''(11), `name` varchar(255) DEFAULT NULL, `address` varchar(255) DEFAULT NULL, `ci'' at line 1: CREATE TABLE people (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY(11), `name` varchar(255) DEFAULT NULL, `address` varchar(255) DEFAULT NULL, `city` varchar(255) DEFAULT NULL, `state` varchar(255) DEFAULT NULL, `zipcode` varchar(255) DEFAULT NULL) ENGINE=InnoDB I''m using a default install. I noticed that the value supplied to PRIMARY KEY was the number 11. Any suggestions. Thanks, Paul --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Possibly Parallel Threads
- Migration - wrong SQL statement is created
- Best Forum? Was: Migration doesn''t seem to preserve create_table options in schema
- Postgresql and ActiveRecords problems
- help:How to set default value for a column use of migration?
- command rake migration also runs #down method ?