I''m getting the error 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), `first_name` varchar(255) DEFAULT NULL, `last_name` varchar(255) DEFAULT N'' at line 1: CREATE TABLE undergraduates (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY(11), `first_name` varchar(255) DEFAULT NULL, `last_name` varchar(255) DEFAULT NULL) ENGINE=InnoDB and I used --trace and it found /home/michael/work/student/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:128:in `log'' /home/michael/work/student/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:243:in `execute'' /home/michael/work/student/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb:104:in `create_table'' /home/michael/work/student/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:353:in `create_table'' /home/michael/work/student/config/../vendor/rails/activerecord/lib/active_record/migration.rb:275:in `send'' /home/michael/work/student/config/../vendor/rails/activerecord/lib/active_record/migration.rb:275:in `method_missing'' /home/michael/work/student/config/../vendor/rails/activerecord/lib/active_record/migration.rb:259:in `say_with_time'' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'' /home/michael/work/student/config/../vendor/rails/activerecord/lib/active_record/migration.rb:259:in `say_with_time'' /home/michael/work/student/config/../vendor/rails/activerecord/lib/active_record/migration.rb:273:in `method_missing'' ./db/migrate//003_create_undergraduates.rb:3:in `real_up'' /home/michael/work/student/config/../vendor/rails/activerecord/lib/active_record/migration.rb:212:in `send'' /home/michael/work/student/config/../vendor/rails/activerecord/lib/active_record/migration.rb:212:in `migrate'' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'' /home/michael/work/student/config/../vendor/rails/activerecord/lib/active_record/migration.rb:212:in `migrate'' /home/michael/work/student/config/../vendor/rails/activerecord/lib/active_record/migration.rb:335:in `migrate'' /home/michael/work/student/config/../vendor/rails/activerecord/lib/active_record/migration.rb:330:in `each'' /home/michael/work/student/config/../vendor/rails/activerecord/lib/active_record/migration.rb:330:in `migrate'' /home/michael/work/student/config/../vendor/rails/activerecord/lib/active_record/migration.rb:297:in `up'' /home/michael/work/student/config/../vendor/rails/activerecord/lib/active_record/migration.rb:288:in `migrate'' /home/michael/work/student/config/../vendor/rails/railties/lib/tasks/databases.rake:4 /usr/lib/ruby/1.8/rake.rb:387:in `call'' /usr/lib/ruby/1.8/rake.rb:387:in `execute'' /usr/lib/ruby/1.8/rake.rb:387:in `each'' /usr/lib/ruby/1.8/rake.rb:387:in `execute'' /usr/lib/ruby/1.8/rake.rb:357:in `invoke'' /usr/lib/ruby/1.8/rake.rb:350:in `synchronize'' /usr/lib/ruby/1.8/rake.rb:350:in `invoke'' /usr/lib/ruby/1.8/rake.rb:1924:in `run'' /usr/lib/ruby/1.8/rake.rb:1924:in `each'' /usr/lib/ruby/1.8/rake.rb:1924:in `run'' /usr/bin/rake:4 I wasn''t sure whether the method missing is the reason behind the error... and I''m not really sure what to do if it is (just learning rails for a class at UC Berkeley). Any help would be appreciated! Thanks Michael -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
OK, figured it out. Apparently MYSQL doesn''t like it when you try to add an "id" as "id". Michael -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
Michael Mike wrote:> OK, figured it out. Apparently MYSQL doesn''t like it when you try to add > an "id" as "id". > > MichaelWhen having rake db:migrate errors, sending the code for the migration that it''s choking on helps us too.... But let''s take your problem and discovered solution a step further. Primary key fields are created by default in your migration by Rails. They are, also by default, named "id". Any field that is a combination of a table name, an underscore and the string "id" will be seen as a foreign key to Rails. Ex. Let''s assume a person owns many things, but a thing can only be owned by 1 person... simplistic but a decent example I think. Imagine your migrations have these. 001_create_people.rb class CreatePeople < ActiveRecord::Migration def self.up create_table :people do |t| t.column :name, :string, :null => false; end end def self.down drop_table :people end end This creates the following table. (id is created automatically and tagged as a primary auto increment key) People Table -=-=-=-=-=-=-id name 002_create_things.rb class CreateThings < ActiveRecord::Migration def self.up create_table :things do |t| t.column :people_id, :integer, :null => false; t.column :description :strig, :null => false; end end def self.down drop_table :things end end Creates this with again id done automatically... Things Table. -=-=-=-=-=-=-=- id description people_id If you have your model defined as (1 to many relationship)... and this is actual complete and valid code. (Just untested lol) class Person < ActiveRecord::Base has_many :things end class Thing < ActiveRecord::Base belongs_to :person end This uses the named field ( people.id -> things.people_id ) in your migration and the relationship mapping (has_many / belongs_to) in your models to know the primary key and foreign key pairs. Let''s assume each table has this data: People Table data. id: 1 name: John Things Table data. (2 rows) id: 1 people_id: 1 description: "A car" id: 2 people_id: 1 description: "A truck" In your code (or the script/console which should be your new best friend while learning rails) you can see the results from this... person = Person.find(1) # Finds the row in People with id 1. puts "My name is: #{ person.name }" person.things.each() { # using lazy loading it get''s the things for a person to satisfy the relationship. puts "I own: #{ t.description }" } Being this: My name is: John I own: A car I own: A truck I hope this was not a waste of time expanding on WHY Mysql (actually RAILS) didn''t like your column named ID. When you dig deeper in to rails you will learn ways to change the ''id'' name for your primary to use something else and also how to supress the creating of surrogate keys in your models. - John -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
> I hope this was not a waste of time expanding on WHY Mysql (actually > RAILS) didn''t like your column named ID. When you dig deeper in to rails > you will learn ways to change the ''id'' name for your primary to use > something else and also how to supress the creating of surrogate keys in > your models. > > > - > JohnDefinately not a waste of time, very thankful for any help I can get, Michael -- 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?hl=en -~----------~----~----~----~------~----~------~--~---